Question

How do I implement the MapKit method

[googleMapView convertPoint:nePoint toCoordinateFromView:pinView];

in Google Maps SDK for iOS?

Was it helpful?

Solution

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];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top