-convertPoint: toCoordinateFromView: method for Google Maps SDK for iOS

How to implement the MapKit method

[googleMapView convertPoint:nePoint toCoordinateFromView:pinView];

in the Google Maps SDK for iOS?

+2
source share
1 answer

You can use something like this:

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

In this case, it pointshould relate to the type of card.

If you have a point relative to another view (for example, pinViewin your case), you need to first convert this to a point relative to the map display. You can do this with the following:

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

So, combine all this:

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

All Articles