【发布时间】:2016-06-21 12:20:33
【问题描述】:
我正在使用标记在我的 iOS 应用程序中显示用户位置。我现在可以使用它,但是随着用户移动它会添加其他标记并且不会删除旧标记。我不能使用 mapview clear,因为这会清除我的所有标记,并且我不想在场景中删除其他标记。我将附上下面的代码。谢谢
- (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");
}
【问题讨论】:
标签: ios objective-c google-maps google-maps-markers google-maps-sdk-ios