我使用MapView,并在其上设置了注释(紫色针脚)和用户位置(这是一个蓝色圆圈)。
由于紫色别针注释将移动,因此我必须将其删除并将其设置为新的地图。
我将其设置为:
CLLocationCoordinate2D coordinate;
coordinate.latitude = 49.2802;
coordinate.longitude = -123.1182;
NSUInteger count = 1;
for(int i = 0; i < 10; i++) {
CGFloat latDelta = rand()*.035/RAND_MAX - .02;
CGFloat longDelta = rand()*.03/RAND_MAX - .015;
CLLocationCoordinate2D newCoord = {coordinate.latitude+latDelta, coordinate.longitude+longDelta};
MyMapAnnotation* annotation = [[MyMapAnnotation alloc] initWithCoordinate:newCoord andID:count++];
[mapView addAnnotation:annotation];
[annotation release];
}
在此之前,我要做一个
[mapView removeAnnotations:mapView.annotations];
但此行还会用蓝点删除我的位置!
如何在不删除我的位置的情况下执行此操作。
在此先感谢您,并致以最诚挚的问候。
最佳答案
一种简单的方法是在删除注释的循环之前添加以下行:
self.mapView.showsUserLocation = NO;
然后在循环之后,将用户位置放回
self.mapView.showsUserLocation = YES;
编辑:我只是看到您没有遍历这些位置来删除它们。我不确定这是否可以解决您的问题。