1
我有一個項目,我需要根據我們得到的位置數組在地圖上顯示一些標記。我們使用自定義標記引腳而不是默認值。一個要求是,如果我們放大超過某個縮放閾值,我們需要顯示更大的標記圖標。所以我們有一個小針圖像和一個大針圖像。基於縮放級別,我們需要顯示更大或更小。我明白一種方法是清除所有標記並重新添加它們。但是,由於其他一些挑戰,該解決方案對我們無效。我需要簡單地替換標記圖標圖像。以下是我的代碼:iOS谷歌地圖SDK替換標記圖標
-(void)updateMarkerImagePinSize {
NSLog(@"Update Marker Image called");
//[self.mapView clear];
UIImage *pinImage;
AtmLocations *atmLocations = [ATMLocatorManager sharedATMLocatorManager].atmLocations;
CLLocationCoordinate2D searchedAddressCoordinate = CLLocationCoordinate2DMake(atmLocations.locations.startLatitude, atmLocations.locations.startLongitude);
[self addSearchLocationMarkerToMap:searchedAddressCoordinate];
NSArray *locationArray = atmLocations.locations.location;
if (locationArray == nil || [locationArray count] == 0){
return;
}
for (Location *location in locationArray) {
CLLocationCoordinate2D markerCoordinate = CLLocationCoordinate2DMake([[[location attributes] latitude] doubleValue], [[[location attributes] longitude] doubleValue]);
GMSMarker *marker = [GMSMarker markerWithPosition:markerCoordinate];
if ([location.attributes.locationType isEqualToString:@"ATM"]) {
if (self.mapView.camera.zoom < kZoomThresoldForMarkerImageSizeChange) {
pinImage = [UIImage imageNamed:@"atm_pin_small"];
} else {
pinImage = [UIImage imageNamed:@"atm_pin"];
}
} else {
if (self.mapView.camera.zoom < kZoomThresoldForMarkerImageSizeChange) {
pinImage = [UIImage imageNamed:@"office_pin_small"];
} else {
pinImage = [UIImage imageNamed:@"office_pin"];
}
}
marker.map = nil;
marker.icon = pinImage;
marker.map = self.mapView;
}
}
不過,我所面臨的問題是,無論是標記圖標圖像依然存在。我該如何更換標記圖像而不顯示兩者?