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'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];
}
Dont implement - (void)mapView:(MKMapView *)mv didUpdateUserLocation:(MKUserLocation *)u
method.
Instead use locationmanager didUpdateToLocation
.
didUpdateUserLocation
is called multiple times without any reason.where didUpdateToLocation
is called when any location changes occurred.
Then u can manually set the mkmapview region in the didUpdateToLocation
method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With