How to get coordinate center of gmsmapview in iphone

萝らか妹 提交于 2019-12-20 17:40:44

问题


I'm using the new Google Maps SDK for iOS

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

Thank and Regards.


回答1:


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

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...




回答2:


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

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



回答3:


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




回答4:


Here is how to do it in Swift 4

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


来源:https://stackoverflow.com/questions/15103390/how-to-get-coordinate-center-of-gmsmapview-in-iphone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!