MobileLocation Lat and Long never change

I’m trying to set some pins on a map in an ios app. I’m using the mobile location and have set up the AuthorizationStateChanged and LocationChanged. Location changed is called by pressing a button and then saving the resulting Lat, Long and references to my database. That all works fine, however the values are always the same. I have accuracy set at best and have stood in different places in my yard. Any ideas?

Go to Settings > Privacy & Security, then select Location Services. Select the app, and make sure that the Precise Location is set to on.

1 Like

it is set to on already, and set to allow while using the app

FWIW the LocationChanged event is raised by the Location instance when the OS detects that, in fact, the location as changed based on the provided settings (accuracy), and not meant to be called “on demand”.

The most precise setting (Best) uses the device GPS signal… and fallbacks to WiFi + Cellular signal when the GPS signal is weak/not available (that is, less precise).

Maybe something of that makes sense to you? Or you can post some code here to see if we can try it.

So I have a button that when pressed calls the MobileLocation1.Start
The LocationChanged Event is

SaveLocation(ID, latitude, longitude) ' just saves the info to the database
MobileLocation1.Stop

The latitude and longitude is always the same as the first entry in the database, no matter where in my yard I am.

Maybe you can expand your tests to 10 meters, 50 meters, 100 meters disabling WiFi and cellular and see how it goes. As said, all that info is provided by the OS itself and it depends widely on where the device is and quality of signals. :person_shrugging:t2:

As you can see here (using Maps), I can be anywhere inside the circle radius… even if I change my position inside the house.

If this is in the simulator, to simulate location changes you need to select driving / cycling / running in the simulator’s menubar

isn’t it just going to be worse if I change from best? I can try it though

no not in the simulator on built ios app on the phone

I just had a look in my iOS App where I use location services. I just start them, but never stop them because I want constant updates.
So maybe remove the stop-line from your code and move around in a much bigger area than your yard.

1 Like

Yeah, I do the same thing for VoyageExpenses iOS app. I start the Location service and don’t stop it while the app is in use. (BTW… it also saves the location to a local SQLite database)

2 Likes

instead of removing the stop, which should also work but drains more battery, I ended up waiting until it changes a significant amount for before stopping and that seems to work. It seems like it take a few seconds before the old location moves out.

Yes, that´s what I found out too when starting to work with location sevices.
I thougt “just ask for the current location and get it - done”.
Unfortunately that´s not how it works. Apple updates the location continuously in the background and gives you an ever more exact location the longer you wait.
Depending on the location of the iPhone (city, woods, high seas) it takes a different time to get an exact location.
Maybe give your users a choice how long they are willing to wait.
Have you tested, how much battery it costs to just leaving it on vs. stopping? I have no idea myself and would be interested, if anyone knows…

1 Like

i have not but I do have mine waiting until the accuracy is <= 5 m. I’d like it more precise than that but don’t know if that is possible. I may have to try setting locations manually if I’m not getting accurate enough locations