如何在iphone中获取gmsmapview的坐标中心

ima*_*ice 24 iphone ios google-maps-sdk-ios

我正在使用适用于iOS的新版Google Maps SDK

我可以从GMSMapView.center获得真正的坐标吗?现在它返回一个CGPoint值,但它不是真正的坐标.

谢谢和问候.

Jin*_*ing 41

使用mapview 的projection方法- (CLLocationCoordinate2D)coordinateForPoint:(CGPoint)point将地图中的点转换为地质坐标

CGPoint point = mapView.center;
CLLocationCoordinate2D coor = [mapView.projection coordinateForPoint:point];
Run Code Online (Sandbox Code Playgroud)


Rex*_*Lam 39

我建议使用[yourMapView.camera target]而不是Jing的解决方案.

Jing的解决方案在iOS 6上运行良好,但可能在iOS 7/7.1上有问题,投影可能报告错误的坐标(有点向下移位)!我已经检查了地图边界和填充是否正确,结果[projection pointForCoordinate: coordinate][projection coordinateForPoint:point]可以相互对比,没有想法问题在哪里...


Sax*_*uce 9

你在找mapView.camera.target?这是一个CLLocationCoordinate2D.


Pab*_*ufo 8

这是如何做到的 Swift 4

let coordinate = mapView.projection.coordinate(for: mapView.center)
Run Code Online (Sandbox Code Playgroud)