-convertPoint:toCoordinateFromView:谷歌地图SDK方法适用于iOS

2019-07-20 08:08发布

如何实现MapKit方法

[googleMapView convertPoint:nePoint toCoordinateFromView:pinView];

在谷歌地图SDK适用于iOS?

Answer 1:

你可以使用这样的事情:

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

在这种情况下point应该是相对于地图视图。

如果你有相对于其他视图(如点pinView你的情况),你需要将其转换成相对于地图视图第一点。 你可以这样做有以下:

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

因此,结合它们放在一起:

GMSMapView* mapView = ...;
UIView* pinView = ...;
CGPoint pinViewPoint = ...;
...
CGPoint mapViewPoint = [pinView convertPoint: pinViewPoint toView: mapView];
CLLocationCoordinate2D coordinate = 
    [mapView.projection coordinateForPoint: mapViewPoint];


文章来源: -convertPoint:toCoordinateFromView: method for Google Maps SDK for iOS [closed]