我是通过objective-c在iPhone应用中使用谷歌地图,没关系,标记位于给定位置。我想在点击特定位置时通过单击地图将标记位置更改为所选位置。 这该怎么做? 提前谢谢。
我的代码:
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:29.964996
longitude:30.939680 zoom:5
bearing:0
viewingAngle:0
];
_mapView = [GMSMapView mapWithFrame:viewOfMap.bounds camera:camera];
_mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth|
UIViewAutoresizingFlexibleHeight;
[_mapView addObserver:self
forKeyPath:@"myLocation"
options:NSKeyValueObservingOptionNew
context:NULL];
[viewOfMap addSubview:_mapView];
dispatch_async(dispatch_get_main_queue(), ^{
//_mapView.myLocationEnabled = YES;
_mapView.myLocationEnabled = YES;
});
GMSMarker *marker = [[GMSMarker alloc] init];
marker.position = CLLocationCoordinate2DMake(lat, lag);
marker.map = _mapView;
答案 0 :(得分:1)
- (BOOL)mapView:(GMSMapView *)mapView didTapMarker:(GMSMarker *)marker
{
marker.icon=[UIImage imageNamed:@"selectedicon.png"];//selected marker
for (int i=0; i<[markerArray count]; i++)
{
GMSMarker *unselectedMarker=markerArray[i];
//check selected marker and unselected marker position
if(unselectedMarker.position.latitude!=marker.position.latitude && unselectedMarker.position.longitude!=marker.position.longitude)
{
unselectedMarker.icon=[UIImage imageNamed:@"unselectedicon.png"];
}
}
return NO;
}
答案 1 :(得分:0)
如果我理解了您的问题,您想要点按某个位置并让标记移动到该位置。
确保视图控制器实现GMSMapViewDelegate
并使用didTapAtCoordinate
委托方法。像这样:
-(void)mapView:(GMSMapView *)mapView didTapAtCoordinate:(CLLocationCoordinate2D)coordinate {
[marker setPosition:coordinate];
}