Separating location manager updates and touches iphone - iphone

I have the location manager updating the current location and I move a pin on my map reflecting the location. However, when the location manager-desired accuracy is at 'best' and you are moving, the updates are almost continuous, so the code when a new location is received is being run constantly. This prevents the user from touching the screen and doing other functions, like zooming, moving changing to another tab, etc. How can I separate these 2 tasks, i.e something whereby the lcoationmanger did update to location method should be running on a parallel thread or something, so that the touches can happen regardless?
Thanks for any inputs!

I don't know if that suite your needs, but it may be better in that case not to use CLLocationManager's delegate, but instead use a scheduler to query it yourself every few seconds.

Related

How to prevent current location from jumping around the map

In my flutter app I have a map, which displays current location. Im using google_maps_flutter plugin, and enabled current location. The problem is, that when Im standing still, the location still moves around.
Can this somehow be prevented? To just completely freeze the map when standing still?
There is nothing wrong at your end, it is just how Google Maps work if it has less accuracy of the current location, it keeps jumping until it finds bit more accuracy.
You may want to test your app outdoor where GPS has better reception of satellites due to clear view of sky.
Try to useLocation package to get current location instead of google map's, you can control the time interval of retrieving current location

core location autopause, effects of activity type

Hi does anyone know the effect that using different CLActivity type constants has on the behavior of auto pause? For example, will the location manager resume from a pause more readily if activityType is set to CLActivityTypeAutomotiveNavigation or CLAcitivtyTypeFitness?
Thanks for your help.
The activity type flags affect the internal auto pause logic. For instance CLActivityTypeFitness is more likely to pause when the user is stationary with no accelerometer motion and when the user is moving fast with accelerometer motion similar to a vehicle and vice versa for CLActivityTypeAutomotiveNavigation. CLActivityTypeOther is supposed to be a catch-all setting for everything else. However the exact logic and thresholds are only known to Apple.
As far as I know, the location updates are only resumed if your app becomes active again, there is no auto-resume depending on the user motion. But you can always start region monitoring in your didPause callback to resume tracking again when the user does move.

IOS Location found detection

Currently I'm building an application which shows nearby advertisements based on the current location. When the user starts the application for the first time I want them to see a top 10 of nearby advertisements.
I'm having a slight problem with fetching the location on time. My problem is that the current location isn't fetched yet before the view is loaded.
Of course there is the delegate UpdatedLocation, but this one gets fired multiple times. I guess it fires multiple times, because it wants to fetch the most accurate location?
So my question is; What can I do to 'wait' until the location is found and then start searching for advertisements?
Thanks in advance!
Regards,
Mittchel
You should update the view every time you get a (more accurate) location. So remember the last location and check whether horizontalAccuracy/verticalAccuracy have decreased (smaller = more accurate, but negative = invalid). Maybe even updating every time you get a new location would be better since the accuracy might not change but the position does (user is moving).
If you just show a list, you should remember the previous results. Fetch the new result and if they differ, update your list.
When CLLocationManager gets an updated hit from the Core Location system, it fires its delegate's didUpdateToLocation:fromLocation: method. Inside that method, you want to do whatever you do when you get an updated location.
In your case, you'll want to check that new location's .horizontalAccuracy property to see that it's a high quality result. You also probably want to chuck the first few, because CL will give you the last hit of the last location session as your first hit of the new one.
Either way, that's the method where you want to do your fetching of data.
There is no one location, you get a series of locations from CL, one cached and then others varying in accuracy over time, getting better (or worse) accuracy, taking anywhere from 1 second to 10 minutes.
CL will start by giving you a cached location, which may be good enough for your purposes. If it's not too old (<60 seconds) and reasonable accuracy, go ahead and use the cached location, it will be the fasted result. Otherwise you have to wait for a sufficiently good accuracy (you have to decide what is sufficient, look at .horizontalAccuracy).
If you insist on having the location before viewDidLoad is called (viewWillAppear would be a better place) then you have to hold off pushing that viewController until you have a sufficient location. How you do that depends on how that view controller is being loaded.
Here is what I would do. Load your view, and in your viewDidAppear, call your method to update location. I have been using a nice open source project on github called MBProgressHUD. It will display a variety of progress indicators on the screen (that will also block the user from leaving your view) while it finishes its work. It also gives a visual feedback to the user that your app hasn't stalled and is working.
You will still need to sort out your accuracy issues, but the progress view gives you time to load the view and keep the user engaged while you pull in what you need. And keeps your UI fluid.

Background location updates for iOS display GPS icon the entire time

My app runs significant location change updates in the background. However the GPS display icon never turns off..even when app is in the background. Is there a way to use location manager with Significant location change in the background and have the GPS icon NOT display continuously? My users don't understand that it is only periodically obtaining location coordinates and instead think its constantly running in background and thus deleting app thinking its too power intensive. Please help.
I believe that any use of CoreLocation will prompt the location arrow. That includes any of the geofencing CLRegion use, -startMonitoringForSignificantLocationChanges, and -startMonitoringForLocation. I think that is Apple's safeguard that something is using your GPS, even in limited use.
That arrow will be visible till you unregister your application from significant change. But I faced problem, what I can't fine point where I can do this. In my case will be best to unregister on application kill, but with multitasking there is no such ability to handle this moment to unregister.

locationManager:didUpdateToLocation:fromLocation not getting called for Significant Location Changes Monitoring

I implemented background location tracking using standard location services, and it works fine. However, since this implementation uses a lot of power, I decided to switch to significant location changes monitoring. Basically, I just changed all the calls to startUpdatingLocation to startMonitoringSignificantLocationChanges and reused the CLLocationManagerDelegate methods I have implemented before.
The problem is that after switching to significant location changes monitoring, the delegate method locationManager:didUpdateToLocation:fromLocation only gets called once when I start monitoring, and is never called again afterwards. I have moved around the phone for a couple of kilometers, and tried riding a train with it, but still the method never gets called. Am I missing something here? Are there settings I need to enable or special code I need to write in order for this to work?
Thanks!
The significant location change requires cell phone towers in order to operate. If you don't have cell phone reception you will not get any results. You can also call CLLocationManager's significantLocationChangeMonitoringAvailable method to see if it is available.