【发布时间】:2016-08-15 17:27:08
【问题描述】:
我正在运行一个线程以每 10 秒获取一次驱动程序位置,并希望从地图中删除添加的标记,但它不起作用..
我的代码:
-(void)APiResponse:(id)returnJson
{
[googleMapsDriverPin setMap:nil];
googleMapsDriverPin = nil;
NSMutableArray *driverPins = [[NSMutableArray alloc]init];
for (int x = 0; x < [[returnJson valueForKey:@"drivers"] count]; x++) {
CLLocation *driverLocations = [[CLLocation alloc]initWithLatitude:[[[[returnJson valueForKey:@"drivers"] objectAtIndex:x] valueForKey:@"driver_latitude"] doubleValue] longitude:[[[[detail valueForKey:@"drivers"] objectAtIndex:x] valueForKey:@"driver_longitude"] doubleValue]];
[driverPins addObject:driverLocations];
}
for (CLLocation *newLocation in driverPins) {
googleMapsDriverPin = [[GMSMarker alloc] init];
[googleMapsDriverPin setPosition:newLocation.coordinate];
[googleMapsDriverPin setAnimated:YES];
[googleMapsDriverPin setTitle:@"title"];
[googleMapsDriverPin setSnippet:@"snippet"];
[googleMapsDriverPin setIcon:[GMSMarker markerImageWithColor:[UIColor blackColor]]];
[googleMapsDriverPin setMap:googleMaps];
}
}
它只是每10秒不断添加和添加,而不是删除,请帮助! 谢谢!
【问题讨论】:
-
使用 MKMapView 时,您可以使用
[mapView removeAnnotations:mapView.annotations]删除所有引脚 -
试试[mapView clear]; (其中 mapView 是您的 GMSMapView); ..or.. [googleMaps clear];如果 googleMaps 是您的 GMSMapView
-
@TonyMkenu 感谢您的回答,问题是,这些标记是驱动程序,我也想在地图上保留 MY CURRENT POSITION 标记,如果我清除地图,它会清除所有标记,我只想每 10 秒更新一次驱动程序位置.. :( 之后尝试添加我当前的位置,但只在需要时显示标记?任何帮助将不胜感激!谢谢
标签: iphone ios objective-c google-maps-sdk-ios