我在我的 iOS 应用程序中实现了 Google map
并显示用户位置,我使用自定义标记图标。一切正常。我已经实现了 GMSMapViewDelegate
。
问题是当我点击标记图标时事件 didTapAtCoordinate:
没有被触发,但是当我点击 map 上的任何地方时它会触发。当我尝试设置它时,只是标记不可点击 marker.tappable = YES;
我已经在互联网上进行了搜索,但找不到我做错或遗漏的地方。
代码如下:
/** SETUP MAP & MARKERS **/
-(void) setupMapMarkers {
self.mapView.delegate = self;
/** SET CAMERA POSITION ON MAP **/
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:[self.userObject.latitude doubleValue]
longitude:[self.userObject.longitude doubleValue]
zoom:10];
self.mapView.camera = camera;
/** ADDING USER'S LOCATION MARKER **/
CLLocationCoordinate2D position = CLLocationCoordinate2DMake([self.userObject.latitude doubleValue], [self.userObject.longitude doubleValue]);
GMSMarker *marker = [GMSMarker markerWithPosition:position];
marker.tappable = YES;
NSURL *url = [[NSBundle mainBundle] URLForResource:@"pin_user_active" withExtension:@"gif"];
marker.icon = [UIImage animatedImageWithAnimatedGIFData:[NSData dataWithContentsOfURL:url]];
marker.map = self.mapView;
}
#pragma mark - GMSMapViewDelegate
- (void)mapView:(GMSMapView *)mapView didTapAtCoordinate:(CLLocationCoordinate2D)coordinate {
NSLog(@"You tapped at %f,%f", coordinate.latitude, coordinate.longitude);
}
// Added it just to check, if it works on tap
- (void)mapView:(GMSMapView *)mapView didTapOverlay:(GMSOverlay *)overlay {
NSLog(@"tapped");
}
最佳答案
给 marker.title = @"some text"并调用这个委托(delegate)方法:
- (void)mapView:(GMSMapView *)mapView didTapInfoWindowOfMarker:(GMSMarker *)marker;
当您点击标题时,将调用此方法。
关于ios - 谷歌地图的自定义标记图标不可点击(使用委托(delegate)),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34469579/