MKUserLocation stops updating when map is touched - ios

I am using MKMapView, and has enabled tracking for current location.
mapView.showsUserLocation = true
mapView.setUserTrackingMode(.FollowWithHeading, animated: false)
When i touch or hold the screen it stops updating. Is it any way to prevent this?
I want the map and user location (blue dot) to continue animating.
Edit:
The same "problem" happens if you touch, zoom or pan in the original iOS Maps app.

This is not a problem. This is how it is supposed to work. In the iOS maps app you can toggle between the three modes (track location, track location and heading, no tracking).
When you have it in either of the tracking modes and the user moves the map the tracking is changed to no tracking.
This is so that you are not overriding what the user has done. Note, it will still keep the blue marker updated for the user's location it just won't track them.
If it didn't do this then when the user tries to scroll the map it would keep jumping back to the user location instead of letting them see what they want to see.
You could change this by disabling the user interaction on the map. But I wouldn't try to override this default behaviour. It is a learned behaviour of how the map works in iOS. Changing it will give the user the impression that it is broken.

Related

How to make iOS 13 map display both the user location and another annotation even when they are close together

By default, in ios12 map, both the user location and another added annotation are displayed together even when their locations are very close. But in ios13 map, the user location will hide another location if they are close together.
If somebody knows how to display the user location and another location together at close proximity in iOS13, please help.
Below is an image generated on a iOS12 phone. On iOS13, everything is the same except that the custom user location image is not displayed.
Both the user location and the added annotation will be displayed (even when they are closely located) if they are both assigned a value of MKFeatureDisplayPriorityRequired.

Location updates issue for iOS 7

I'm developing an iOS map application, so it's essential to receive location data consistently.
What is happening now is that the system allows the to app load the map and that's it!
The location getting instruction seems to freeze, even the network traffic indicator at the top bar disappears. Simply when I go to Settings->Privacy->Location Updates, switch off location updates for my app and then switch it back on. The map loads the current location.
What could be the possible causes to this?, please advice.
Use:
[_mapView setUserTrackingMode:MKUserTrackingModeFollow animated:YES];
This will smoothly follow the users current location. If you drag the map it will even set the tracking mode back to MKUserTrackingModeNone which is usually the behaviour you want.

What is your data loading strategy for pins on the map on the iOS?

I have developed an iOS app with native map showing custom pins on the map? Data behind the pins is loaded on demand and based on the movement around the map. I am setting a radius based on the current position and if the map goes out of this region it will send for data update.
At first new pins are loading smoothly but sometimes I have a feeling they are lagging especially for quick swipes.
So what strategies are you using in this case?
Apps that I have worked on that have maps I normally use the bounding box rather than radius as it is a perfect match for the screen ie rectangular.
As for loading new pois when a user moves, I would wait until they have stopped scrolling the map. If your users are doing quick swipes you could always detect that the map has moved and cancel any existing requests that were being executed until the user stops moving again.

MKMapView Loads before LocationManager has got user location - cannot set Region to center on user location

I have an iOS app where Im loading a MKMapView as the app starts. I want to set the center of the "MKCoordinateRegion" to be the user latitude/longitude. However, the CLLocation Manager instance does not update the user location until after the MKMapView has loaded.
For now I am hard coding the map center coordinates into the app. But I was wondering if anyone can suggest a better way to handle this situation.
I can think of 2 approaches but Im not a fan of either of them:
1) Stall launching the MKMapView using an activityindicator
2) Launch the MKMapview with the hard coded location and then as soon as the user location is available animate the mapview region to center on that location
Any suggestions?
Store the last known lat/long when you go to background or when app is closed.
On start center map view to last known position.
As soon as location manager sends an updated location, update the map center.
Set the userTrackingMode property of the mapview to MKUserTrackingModeFollow. You don't need a location manager for this, mapView does it for you. When you later want to relocate the map, set the property to MKUserTrackingModeNone, and relocate your map.
Do what Apple does. Start really far zoomed out, maybe put a message on screen "Scanning for location", then when the location information is available zoom in.

MapKit/CoreLocation/ShowsUserLocation implementation strategy

I'm implementing a map in one of my apps, the user's location needs to be read and then the map zoomed to current location and then pins added for businesses surrounding the user.
I've got it working to a point but i'm confused as to how to implement the current location stuff.
I tried adding a MKMapView and setting showsUserLocation = YES which in the simulator will always annoyingly place you at Apple's HQ in CA, no good to me for testing!
So, I thought i'd implement CoreLocation which works brilliantly and in the simulator, uses the network/WiFi mapping to figure out that i'm at home and returns lat/long for my home.
However, so far, I can only represent the current location with a MKPinAnnotationView setting it to a green dot. This animates nicely onto my map but what i'd really like though is to have the blue dot as my current location annotation with the circle around it similar to showsUserLocation.
Is there a way in a delegate protocol for MKMapView to intercept how the showsUserLocation = YES internals work to accomplish this? Or, can I reset the co-ordinates that it thinks are right to display my actual location?
The simulator is displaying the Apple's HQ because it doesn't have a GPS chip available.
I'd recommend to test your code on a device and use showUserLocation = YES in order to show the user's current location.
The hack you are trying to do is not recommended.

Resources