与此委托方法的问题是“在滚动,这种方法可称为多次上报更新的地图位置”(所以你需要IF/THEN或CASE/BREAK等,以保持它的“轻量级“)。你不需要使用这个方法(不是必需的),但是如果你想要合并某种功能(例如去除无用的引脚等),那么保持它轻量级的示例代码将是:
- (void)mapView:(MKMapView *)mapView regionWillChangeAnimated:(BOOL)animated{
if(!animated){
//Instantaneous change, which means you probably did something code-wise, so you should have handled anything there, but you can do it here as well.
} else {
//User is most likely scrolling, so the best way to do things here is check if the new region is significantly (by whatever standard) away from the starting region
CLLocationDistance *distance = [mapView.centerCoordinate distanceFromLocation:originalCoordinate];
if(distance > 1000){
//The map region was shifted by 1000 meters
//Remove annotations outsides the view, or whatever
//Most likely, instead of checking for a distance change, you might want to check for a change relative to the view size
}
}
}
哦所以注释视图不会自动纠正其位置? – quantumpotato 2011-01-31 13:31:28