0

In my MKMapView, I am trying to update the MKCoordinateRegion every time didUpdateLocations is called with the new location. However, the problem is that when I do this, it zooms out to the original MKCoordinateRegion that I set in viewDidLoad and then it zooms in to the new region. This is a horrible UX

In didUpdateLocations I am doing:

MKUserLocation *userLocation = _mapView.userLocation;
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance (userLocation.location.coordinate, newHeight, newWidth);
    [_mapView setRegion:region animated:NO];

Any ideas?

Jesse
  • 2,674
  • 6
  • 30
  • 47
  • Can you provide some more information? didUpdateLocations - consist only these two line or something more? – viral Apr 22 '14 at 17:53
  • Just change the map's centerCoordinate instead of the whole region. Note that setting userTrackingMode to MKUserTrackingModeFollow may let you avoid this manual updating completely. –  Apr 22 '14 at 17:58
  • I do have MKUserTrackingModeFollow set, and I can't just change the center coordinate, because in my map I am trying to show only the region between the user and a pin and that pin could be 200ft away or it could be 3000 miles away – Jesse Apr 22 '14 at 18:02
  • This is a locator app and so the user may start out being 500 meters from the annotation, but as they get closer to the annotation, i want to change the zoom of the map so it is more zoomed in as they get closer to the destination – Jesse Apr 22 '14 at 18:03
  • Then the question is how you're setting newHeight and newWidth in didUpdateLocations. In iOS 7, you can use the showAnnotations method to do the region calc for you. If your app needs to work on lower than iOS 7, then there's a better way to calc the region. –  Apr 22 '14 at 18:05
  • CLLocationDistance distanceInMeters = [curLocation distanceFromLocation:annotationLocation]; – Jesse Apr 22 '14 at 18:06
  • curLocation is the location from the didUpdateLocations method – Jesse Apr 22 '14 at 18:07
  • I will look into showAnnotations, that may be what i need. I don't care about pre iOS 7 – Jesse Apr 22 '14 at 18:07
  • Please show the exact code that sets newHeight and newWidth. Also, if you're going to be updating the region manually (which includes calling showAnnotations), you might want to set userTrackingMode to None. –  Apr 22 '14 at 18:08
  • I managed to locate this answer which is exactly what I needed: http://stackoverflow.com/a/10568267/679439 – Jesse Apr 22 '14 at 18:17

0 Answers0