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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15103390/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 22:28:27  来源:igfitidea点击:

How to get coordinate center of gmsmapview in iphone

iphoneiosgoogle-maps-sdk-ios

提问by imalice

I'm using the new Google Maps SDK for iOS

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

Can I get the true coordinate form GMSMapView.center? Now it returns a value of CGPoint, but it's not the true coordinate.

我可以获得 GMSMapView.center 的真实坐标形式吗?现在它返回 CGPoint 的值,但它不是真正的坐标。

Thank and Regards.

谢谢和问候。

回答by Jing

Use the projectionmethod - (CLLocationCoordinate2D)coordinateForPoint:(CGPoint)pointof the mapview to convert a point in the map to the geological coordinates

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

CGPoint point = mapView.center;
CLLocationCoordinate2D coor = [mapView.projection coordinateForPoint:point];

回答by Rex Lam

I suggest to use [yourMapView.camera target]instead of Jing's solution.

我建议使用[yourMapView.camera target]代替 Jing 的解决方案。

Jing's solution work fine on iOS 6, but maybe having issue on iOS 7/7.1, the projection may report wrong coordinate (a bit downward shift) ! I have checked the map bounds and padding is correct, both result of [projection pointForCoordinate: coordinate]and [projection coordinateForPoint:point]can contrast to each other, no ideas where the problem is...

Jing 的解决方案在 iOS 6 上工作正常,但可能在 iOS 7/7.1 上有问题,投影可能会报告错误的坐标(有点向下移动)!我检查了地图边界和填充是正确的,两种结果[projection pointForCoordinate: coordinate],并[projection coordinateForPoint:point]可以对比对方,没有观念问题出在哪里?

回答by Pablo Marrufo

Here is how to do it in Swift 4

这是如何做到的 Swift 4

let coordinate = mapView.projection.coordinate(for: mapView.center)

回答by Saxon Druce

Are you looking for mapView.camera.target? This is a CLLocationCoordinate2D.

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