我正在尝试从Google地图中移除现有的所有标记,我们可以通过map.clear
执行,但我不想删除地图上的所有内容(折线,多边形),我只想删除标记
我正在根据数组计数
创建标记-(void)annotationCreationForCoordinatesOfArray:(NSMutableArray *)array
{
for (int i=0; i<array.count; i++)
{
CLLocationCoordinate2D position = CLLocationCoordinate2DMake([[[array objectAtIndex:i] objectForKey:@"latitude"] doubleValue], [[[array objectAtIndex:i] objectForKey:@"longitude"] doubleValue]);
mark = [GMSMarker markerWithPosition:position];
NSString *annoNumber = [NSString stringWithFormat:@"%i",i];
mark.title = annoNumber;
mark.map = _mapView;
mark.tracksViewChanges = YES;
mark.draggable = YES;
mark.icon = [UIImage imageNamed:@"Mappin.png"];
}
}
答案 0 :(得分:0)
试试这段代码吧。
创建全局数组
NSMutableArray *removalMarkerArray;
现在在全局数组中添加所有标记
removalMarkerArray=[[NSMutableArray alloc]init];
-(void)annotationCreationForCoordinatesOfArray:(NSMutableArray *)array{
for (int i=0; i<array.count; i++){
CLLocationCoordinate2D position = CLLocationCoordinate2DMake([[[array objectAtIndex:i] objectForKey:@"latitude"] doubleValue], [[[array objectAtIndex:i] objectForKey:@"longitude"] doubleValue]);
mark = [GMSMarker markerWithPosition:position];
NSString *annoNumber = [NSString stringWithFormat:@"%i",i];
mark.title = annoNumber;
mark.map = _mapView;
mark.tracksViewChanges = YES;
mark.draggable = YES;
mark.icon = [UIImage imageNamed:@"Mappin.png"];
[removalMarkerArray addObject:mark];
}
}
然后在哪里清除所有标记
for (GMSMarker *marker in removalMarkerArray ){
marker.map = nil;
}