2

我使用 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];

但是这条线也用蓝点删除了我的位置!我怎么能在不删除我的位置的情况下做到这一点。

非常感谢提前和最好的问候。

4

1 回答 1

3

一个非常简单的方法是在删除注释的循环之前包含这一行:

    self.mapView.showsUserLocation = NO;

然后在循环之后,将用户位置放回

    self.mapView.showsUserLocation = YES;

编辑:我刚刚看到你没有遍历这些位置来删除它们。我不确定这是否适用于您的操作方式。

于 2010-01-14T11:09:35.827 回答