I seem to have the opposite problem from many of those posted here about MKMapView
. Rather than not being able to get it to zoom to and display the current location, I can't seem to get it to stop doing so. Here's what happens:
- I launch the app
- The MKMapView shows my location with a blue dot
- I zoom out and away on the map using my fingers
- After a few seconds, the MKMapView suddenly zooms back in to center on my current location again
I've tried telling my CLLocationManager
to stopUpdatingLocation
(no effect, since an MKMapView
knows how to use CoreLocation
), and I've tried telling the MKMapView
to setShowsUserLocation:NO
(no blue dot displayed at all, which is not what I want). I even tried eliminating my CLLocationManager
(no effect). What is causing this and how do I stop it?
Yes, I do set the location manager's accuracy and distance in -loadView
.
I don't implement -mapViewDidFinishLoadingMap
:. Here is my implementation of
-locationManager:didUpdateToLocation:fromLocation:
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
// How many seconds ago was this new location created?
NSTimeInterval t = [[newLocation timestamp] timeIntervalSinceNow];
// CLLocationManagers will return the last found location of the device first,
// you don't want that data in this case. If this location was made more than 3
// minutes ago, ignore it.
if (t < -180)
{
// This is cached data, you don't want it, keep looking
return;
}
[locationManager stopUpdatingLocation];
}
I think this is the centering you're asking about, @Anna Karenina:
- (void)mapView:(MKMapView *)mv didUpdateUserLocation:(MKUserLocation *)u
{
CLLocationCoordinate2D loc = [u coordinate];
// Display the region 500 meters square around the current location
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(loc, 500, 500);
[mv setRegion:region animated:YES];
}
mapView:didUpdateUserLocation:
? Can you post that code? – Cockup