0

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.

2
  • are you doing your testing on the device or simulator? do you do anything when the user touches in the map view? if so, what does that code look like? Mar 14, 2016 at 2:06
  • The problem occurs both on device and simulator. Im using touchesbegan/ended/cancelled on a MKAnnotationView Subclass, but nothing on the mapview directly. I have also tried to create a new project with only a mapview, no subclassing, problem still occurs.
    – Espen Birk
    Mar 14, 2016 at 6:13

1 Answer 1

0

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.

7
  • Thanks Fogmeister. I was afraid this was not a bug.. It works exactly as you describes, and it makes sense, EXCEPT that the blue dot does not update if you touch/pan/zoom. As soon as i release my finger from the screen it does one out of two things, depending on how far the blue dot should've traveled. 1: If its a short distance, its animated towards the new location. 2: If its a long distance (f.example driving) it jump straight to the new location. I want the map to stop tracking/following, but i need the blue dot to continue.
    – Espen Birk
    Mar 14, 2016 at 15:34
  • @EspenBirk I have an app that uses the map to track the user and show the current location. When I touch/pan/zoom the blue circle (with the white border and the radar ping thingy) moves exactly as the map moves. Please show more code. If yours doesn't do this then there must be something you are doing that interrupts it. Also, note that you don't need to intercept touches to touch, pan and zoom the map. It does this on its own without needing any code.
    – Fogmeister
    Mar 14, 2016 at 15:46
  • @EspenBirk if you need to get info from the map then maybe the MKMapViewDelegate is a better option.
    – Fogmeister
    Mar 14, 2016 at 15:46
  • Hi Fogmeister, thanks for replying. I am conforming the MKMapViewDelegate. I have not implementet touch, pan or zoom, just using the original mapview in a ViewController setup via Storyboards. I tried creating a new project with only 1 view controller, 1 map, conforming the delegate and using the two properties in my original post, same thing happends there. The same thing happens in iOS Maps (the apps thats shipped with iOS). Ill make a screen recording and post a video soon if its allowed to post video urls
    – Espen Birk
    Mar 14, 2016 at 18:22
  • @EspenBirk you can't post a video url but stick it on YouTube and link it. I don't know if I understand what you're describing because the iOS maps app on my phone doesn't do what you're saying.
    – Fogmeister
    Mar 14, 2016 at 18:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.