我正在使用标记来显示iOS应用程序中的用户位置。我现在正在工作,但随着用户的移动,它添加了额外的标记并且不会删除旧标记。我无法使用mapview清除,因为它清除了我所有的标记,还有其他标记我不想在场景中被删除。我将附上下面的代码。谢谢谷歌地图iOS标记不删除
- (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context {
CLLocation *location = [change objectForKey:NSKeyValueChangeNewKey];
mapIcon = @"largemapicon";
GMSMarker *myMarker;
CLLocationCoordinate2D coordi=location.coordinate;
myMarker = nil;
myMarker=[GMSMarker markerWithPosition:coordi];
// marker.snippet = coordinates[@"name"];
myMarker.map = self.mapView;
myMarker.appearAnimation = kGMSMarkerAnimationPop;
UIImage * image = [UIImage imageNamed:mapIcon];
CGSize sacleSize = CGSizeMake(45, 45);
UIGraphicsBeginImageContextWithOptions(sacleSize, NO, 0.0);
[image drawInRect:CGRectMake(0, 0, sacleSize.width, sacleSize.height)];
UIImage * resizedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
myMarker.icon = resizedImage;
NSLog(@"movement");
}
完美!谢谢。 –