ios - 谷歌地图 iOS sdk 获取点击叠加坐标

标签 ios objective-c google-maps google-maps-sdk-ios gmsmapview

我正在使用 Google map iOS SDK。 我想在用户点击叠加层时获取触摸点的坐标。

有这个委托(delegate)方法:

- (void)mapView:(GMSMapView *)mapView didTapAtCoordinate:(CLLocationCoordinate2D)coordinate

但当您点击叠加层或标记时它不会被调用。

我可以通过编程方式调用它吗(但是缺少坐标参数——这就是我想要的……)? 或者从这里获取位置:

- (void) mapView: (GMSMapView *) mapView  didTapOverlay: (GMSOverlay *) overlay

任何建议都是宝贵的!

谢谢!

最佳答案

2015 年 6 月 2 日更新

只需将 UITapGestureRecognizer 钉在 map 上,然后从触摸点提取坐标。您的 didTapAtCoordinate 和 didTapAtOverlay 将像以前一样继续触发。

  UITapGestureRecognizer *touchTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapTouchTap:)];
  [self.view addGestureRecognizer:touchTap];

-(void)tapTouchTap:(UITapGestureRecognizer*)touchGesture
{
  CGPoint point = [touchGesture locationInView:self.view];
  CLLocationCoordinate2D coord = [self.mapView.projection coordinateForPoint:point];
  NSLog(@"%f %f", coord.latitude, coord.longitude);
}

原帖

您可能遗漏了两段代码。 在头文件中采用 GMSMapViewDelegate:

@interface Map : UIViewController <GMSMapViewDelegate>

您还需要在 viewDidLoad 中设置委托(delegate):

self.mapView.delegate = self;

现在这应该为你触发:

- (void)mapView:(GMSMapView *)mapView didTapAtCoordinate:(CLLocationCoordinate2D)coordinate
{
    NSLog(@"You tapped at %f,%f", coordinate.latitude, coordinate.longitude);
}

关于ios - 谷歌地图 iOS sdk 获取点击叠加坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23857744/

相关文章:

google-maps - Google Geocoding API 返回错误的地址,但 Google map 显示正确的位置

ios - 如何在某些生命周期事件之前/之后初始化 ViewController 的安全属性?

ios - 4英寸模拟器奇怪的结果

ios - ScrollView 中的编程式 UIButton

iphone - 如何在 iPhone 中播放 URL 中的视频

android - 地理点 android 和谷歌地图上的 onClick 监听器

ios - iOS-Phonegap-条码扫描器

objective-c - 展示技能树并与之交互的最佳方式是什么

ios - 在另一个动画结束时提交一个不同的动画

google-maps - 安装 SSL 证书后 Google 地理编码 API 停止运行