Search code examples
iosuiviewgoogle-maps-sdk-ios

Get touch position google maps iOS


GMSMapView creates a UIView that handles gestures recognizer, I want detect where in the UIView the user is giving a touch, I can get the marker position (relative to map coordinates) but I want the current position of the touch on the view. Any ideas?.


Solution

  • If I got the question right, you want to calculate CGPoint of touch location in Map's UIView?

    So, you have a CLLocationCoordinate2D you got from Delegate's method, you can get it's position by calling on GMSProjection object on you GMSMapview like:

    - (void)mapView:(GMSMapView *)mapView didTapAtCoordinate:(CLLocationCoordinate2D)coordinate {
     CGPoint locationInView = [mapView.projection pointForCoordinate:coordinate]; // capitalize the V
    }
    

    and the locationInView will be the desired location. So, the GMSProjection's method

    - (CGPoint)pointForCoordinate:(CLLocationCoordinate2D)coordinate;
    

    gives you point of touch in Map's view.

    Hope it helps :)