-convertPoint:toCoordinateFromView: method for Google Maps SDK for iOS [closed]

北城余情 提交于 2019-11-29 15:22:15

You could use something like this:

GMSMapView* mapView = ...;
CGPoint point = ...;
...
CLLocationCoordinate2D coordinate = 
    [mapView.projection coordinateForPoint: point];

In this case point should be relative to the map view.

If you have a point relative to another view (eg pinView in your case), you'd need to convert that into a point relative to the map view first. You could do that with the following:

UIView* pinView = ...;
CGPoint pinViewPoint = ...;
...
CGPoint mapViewPoint = [pinView convertPoint: pinViewPoint toView: mapView];

So combining it all together:

GMSMapView* mapView = ...;
UIView* pinView = ...;
CGPoint pinViewPoint = ...;
...
CGPoint mapViewPoint = [pinView convertPoint: pinViewPoint toView: mapView];
CLLocationCoordinate2D coordinate = 
    [mapView.projection coordinateForPoint: mapViewPoint];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!