Hi Everyone, I know this topic has been looked at before so sorry if it seems like I'm revisiting it. I'm having issues when I leave or enter a geofence it won't register and send my location to google sheets, i've looked everywhere for some kind of hint. I've tried several ways to solve this and have even used an example aia I
found but still cannot get it to work, any help would be more than appreciated. I'm new still and know i'm not brilliant so please spell things out for me lol.
Is your app awake when the app attempts to send your data to the google sheet.? You are doing a LOT of processing within the LocationSensor,LocationChanged event handler. That is usually not a great idea and may be part of your issue.
Can you send a location to your Googlesheet using a Button and a Post command. It that works and your existing code does not, how you use your if..then statements in this Block is possibly the issue.
Your code is very complex, it uses a TinyDB, a FirebaseDB and a google sheet, multiple if statements to determine whether in or not within the boundary created by the Circle (when only a single if/else is necessary). The code need not be that complex.
Get your ringed fence to work the way you want Samuel. Test it then add the 'interesting features'.
The app is active when I leave or try entering back into the geo fence. It sends data to the Google sheet when I'm in the boundary but doesn't when I return, it also sends it multiple times where as I only want it to once for example when I'm in the boundary and when I leave the boundary.the tinydb I use to store the home address from when the app is first used to create the geofence location. I used the firedb so I can track the location on another app. I'm trying to create a app for drivers at my work so I know when they have left home and when they return. I'm not sure how I could simplify it. Thank you for the above advice but could you show me as I've tried everything I can think of.
Then look at how your logic works regarding posting incoming or outgoing the fence with respect to the google sheet. Get the basic part working first (posting in or out or whatever on the sheet).
Sorry, there is too much extraneous code to provide a solution. You got to do it and debugging a lot of complex code is not fun; so simplify. Build an app just to record arriving departing the circle might be a good idea. If not this community has a for hire section.
Here are some resources to help you learn to use the AI2 tools. A very good way to learn App Inventor is to read the free Inventor's Manual here in the AI2 free online eBook App Inventor 2 Book: Create Your Own Android Apps ... the links are at the bottom of the Web page. The book 'teaches' users how to program with AI2 blocks.
give it a try. Also consider the difference between 10 and 30 meters is dangerously close to the Accuracy of the LocationSensor property. You might experiment with those values.
Alternatively to your in/out criteria, consider something like
I would have more confidence that that would work to accomplish your goal better than 'fixing' your method. It just tests whether in or out of the circle. Isn't that all you really care about?
I've got the geofence working as I need, the only problem I'm still having is the map and geofence doesn't show up properly initially, i have to press the refresh button for it to show up or the meters from goefence shows incorrect data
updating the Map initially takes from 30 seconds to a minute to update while the gps decides where it is at; subsequent satellite fixes take a shorter interval depending on the gps hardware. You do not indicate what value you use for the LocationSensor.TImeInterval or the Clock.TimerInterval; these settings could be factors. The Map requires an Internet connect; it can be WIFI or your cell data while mobile. WIFI is fast, data is usually slower and the map tiles from OpenStreetMap take some time to download.
Possibly a timing issue depending on what the 'incorrect data' means. Only you can test this app and debug it. Your circle, at least initially has a 20 m radius, you are trying to check for 15 meters inside the circle which means you are testing to resolve perhaps 5 meters. Depending on the Accuracy of the satellite fix, this can be dangerous. I wouldn't rely upon such dubious precision. I suggested you check for in/out differently; did you try the suggestion made earlier?
You still send data to Firebase at the same time sending to your GoogleSheet. This might be OK but perhaps you should do this differently (using a Button or a separate Clock).