当用户移动时,我的mapView显示用户位置更新时的使用注释数。我想知道userAnnotion如何在用户位置更改时仅显示一次。
[self.myMapview removeAnnotation:userAnnotation];不工作
-(void) viewDidLoad
{
[super viewDidLoad];
[locationManager startUpdatingLocation];
}
-(void) checkLongLatitudeAgain {
[locationManager startUpdatingLocation];
}
-(void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
userlat=self.lastLocation.coordinate.latitude;
userlong=self.lastLocation.coordinate.longitude;
CLLocationCoordinate2D userCord =
{userlat, userlong};
Pins *userAnnotation =
[[Pins alloc] initWithCoordinate:userCord];
[userAnnotation setTypeOfAnnotation:CUR_ANNOTATION];
if (newLocation.coordinate.latitude != self.lastLocation.coordinate.latitude &&
newLocation.coordinate.longitude != self.lastLocation.coordinate.longitude) {
[self.myMapView removeAnnotation:userAnnotation];
self.lastLocation = newLocation;
userlat=self.lastLocation.coordinate.latitude;
userlong=self.lastLocation.coordinate.longitude;
CLLocationCoordinate2D userCord =
{userlat, userlong};
Pins *userAnnotation =
[[Pins alloc] initWithCoordinate:userCord];
[userAnnotation setTypeOfAnnotation:CUR_ANNOTATION];
[self.myMapView addAnnotation:userAnnotation];
}
}
答案 0 :(得分:0)
将annotation
设为全局变量,并在didUpdateLocation: