Search code examples
iosgoogle-maps-markersgoogle-maps-sdk-ios

Get the lat/long coordinates of a marker inside a PanoramaView


According to the Google Maps iOS SDK, I instanciate my panoramaView like this :

import UIKit
import GoogleMaps

class DemoViewController: UIViewController,GMSPanoramaViewDelegate {

  override func viewDidLoad() {
    super.viewDidLoad()
    let panoramaNear = CLLocationCoordinate2DMake(50.059139, -122.958391)

    let panoView = GMSPanoramaView.panoramaWithFrame(CGRectZero,
        nearCoordinate:panoramaNear)

    self.view = panoView;
  }
}

When I tap on the panoramaView, I'd like to get the latitude and longitude I just tapped.

This delegate method is what I need

- (void) panoramaView:      (GMSPanoramaView *)     panoramaView
didTap:         (CGPoint)   point  

I'm stucked with the last part which is to convert this CGPoint into a CLLocation2DCoordinates ! I don't need the pitch, heading etc... I need the lat/long tuple.

Is there a way to handle these locations or this is just not possible in a panoramaView ?

Thanks in advance :)


Solution

  • A CGPoint is not in any way linked to CLLocationCoordinate2D. A CGPoint refers to a point (x,y) in a given rectangle, probably a CGRect that is defined by a certain CGSize.

    You can not access a CLLocationCoordinate2D through the object defined in this delegate method.

    You do get a CLLocationCoordinate2D through:

    • - (void)panoramaView:GMSPanoramaView *)view didMoveToPanorama:(GMSPanorama *)panorama nearCoordinate:(CLLocationCoordinate2D)coordinate and
    • - (void)panoramaView:(GMSPanoramaView *)view error:(NSError *)error onMoveNearCoordinate:(CLLocationCoordinate2D)coordinate