ate*_*t15 4 google-maps objective-c ios google-maps-sdk-ios gmsmapview
我正在使用Google地图iOS sdk.我想在用户点击叠加层时获取触摸点的坐标.
有这种委托方法:
- (void)mapView:(GMSMapView *)mapView didTapAtCoordinate:(CLLocationCoordinate2D)coordinate
Run Code Online (Sandbox Code Playgroud)
但是点击叠加层或标记时不会调用它.
我能以编程方式调用它(但是缺少坐标参数 - 这就是我想要的......)?或者从这里得到位置:
- (void) mapView: (GMSMapView *) mapView didTapOverlay: (GMSOverlay *) overlay
Run Code Online (Sandbox Code Playgroud)
任何建议都很珍贵!
谢谢!
更新2015年6月2日
只需将UITapGestureRecognizer装订到地图上,然后从触摸点提取坐标.你的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);
}
Run Code Online (Sandbox Code Playgroud)
原始邮政
您可能错过了两段代码.在头文件中采用GMSMapViewDelegate:
@interface Map : UIViewController <GMSMapViewDelegate>
Run Code Online (Sandbox Code Playgroud)
您还需要在viewDidLoad中设置委托:
self.mapView.delegate = self;
Run Code Online (Sandbox Code Playgroud)
现在这应该为你解雇:
- (void)mapView:(GMSMapView *)mapView didTapAtCoordinate:(CLLocationCoordinate2D)coordinate
{
NSLog(@"You tapped at %f,%f", coordinate.latitude, coordinate.longitude);
}
Run Code Online (Sandbox Code Playgroud)
如果你只想获取标记的位置,有一个position属性
CLLocationCoordinate2D coord = marker.position;
Run Code Online (Sandbox Code Playgroud)
当这个委托方法被调用时
- (void)mapView:(GMSMapView *)mapView didTapAtCoordinate:(CLLocationCoordinate2D)coordinate
Run Code Online (Sandbox Code Playgroud)
根据我的经验,它用于没有标记或覆盖的屏幕点击。
GMSOverlay 有点不同,因为它是 GMSMarker 的超类。您只需为自定义叠加层创建 GMSOverlay 子类并添加位置属性即可。当您创建叠加层时,例如在 didTapAtCooperative 中,您可以在其中分配位置(GPS 坐标)。
归档时间: |
|
查看次数: |
7484 次 |
最近记录: |