我的应用程序中有一张 map ,我在 map 打开时设置中心用户位置。 我用过这段代码:
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];
}
但是当我移动 map 时它又回到了用户位置。 如何在不关心用户位置的情况下自由移动到我的 map ?
最佳答案
这是因为每次用户位置更改时您都在重置位置。您应该只执行一次,例如
-(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;
}
}
centerToUserLocation
类似于 @property (nonatomic) BOOL centerToUserLocation
关于ios - 为什么我的用户位置总是在中心?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28497973/