我正在使用 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/