开发者

iPhone - remove pin annotations of map, but not mine

I use a MapView and I set annotations on it (purple pins) and my user location (which is a blue circle). Because the purple pin annotations will move, I have to remove and set them new to the map.

I set it with:

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 开发者_StackOverflow社区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];
}

Before that, I do a

[mapView removeAnnotations:mapView.annotations];

but this line also remove my location with the blue point! How could I do this without removing my location.

Thanks a lot in advance & Best Regards.


A very easy way to do this is to include this line before the loop where you remove the annotations:

    self.mapView.showsUserLocation = NO;

and then after the loop, put the user location back in

    self.mapView.showsUserLocation = YES;

EDIT: I just saw that you didn't loop through the locations to remove them. I'm not sure if this will work with the way you do it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜