1

i have a map in my app,i set the center user location when map is open. I have used this code:

 map.delegate=Self; 
 ......
-(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation {

MKCoordinateRegion mapRegion;
mapRegion.center = self.mapView.userLocation.coordinate;
mapRegion.span = MKCoordinateSpanMake(0.5, 0.5); //Zoom distance
[self.mapView setRegion:mapRegion animated: YES];
}

But when i move map it came back to user location. How can i move free into my map without care user location?

Bryan Chen
  • 45,816
  • 18
  • 112
  • 143

1 Answers1

2

This is because you are resetting the location every time the user's location changes. You should do this only once, e.g.

-(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation {

    if (self.centerToUserLocation)
    {
        MKCoordinateRegion mapRegion;
        mapRegion.center = self.mapView.userLocation.coordinate;
        mapRegion.span = MKCoordinateSpanMake(0.5, 0.5); //Zoom distance
        [self.mapView setRegion:mapRegion animated: YES];
        self.centerToUserLocation = NO;
    }
}

Where centerToUserLocation is something like @property (nonatomic) BOOL centerToUserLocation

hypercrypt
  • 15,389
  • 6
  • 48
  • 59