ios - 谷歌地图的自定义标记图标不可点击(使用委托(delegate))

标签 ios objective-c iphone google-maps

我在我的 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/

相关文章:

android - 从服务器添加字符串本地化文件

ios - 将应用内购买添加到 Open Feint 支持的游戏中

ios - 如何在一个应用程序中迁移多个 Realm 文件

objective-c - 滚动时图像加载到错误的 UITableViewCell 上

objective-c - 此 bundle 无效 - 文件扩展名必须是 .zip

objective-c - 存储可从所有用户帐户访问的应用程序数据的最佳方式是什么?

ios - Realm LinkingObjects 第二级返回零

ios - UITabBarController 应用程序和pushViewController 失败

iphone - 函数和过程之间的区别?

iOS 6 : push notifications