Impossible d'afficher ma position dans Google Maps dans iOS 8

J'essaie d'utiliser Google Maps pour iOS dans un projet Swift pour iOS 8. J'ai ajouté l'en-tête de binding Objective-C et ajouté le SDK Google Maps comme indiqué dans la documentation . Et j'ai essayé cet exemple et ça marche très bien.

J'avais besoin de montrer ma position actuelle. J'ai placé les coordonnées pour un location personnalisé dans mon simulateur iOS 8 et modifié le code comme indiqué dans cette réponse StackOverflow. Voici la version Swift.

import UIKit import Foundation class MapViewController: UIViewController { @IBOutlet var mapView: GMSMapView! var firstLocationUpdate: Bool? override func viewDidLoad() { super.viewDidLoad() let camera = GMSCameraPosition.cameraWithLatitude(-33.86, longitude: 151.20, zoom: 12) mapView = GMSMapView.mapWithFrame(CGRectZero, camera: camera) mapView.settings.compassButton = true mapView.settings.myLocationButton = true mapView.addObserver(self, forKeyPath: "myLocation", options: .New, context: nil) dispatch_async(dispatch_get_main_queue(), { () -> Void in self.mapView.myLocationEnabled = true }) println(mapView.myLocation) view = mapView let marker = GMSMarker() marker.position = CLLocationCoordinate2DMake(-33.86, 151.20) marker.title = "Sydney" marker.snippet = "Australia" marker.map = mapView } override func observeValueForKeyPath(keyPath: Ssortingng!, ofObject object: AnyObject!, change: [NSObject : AnyObject]!, context: UnsafeMutablePointer<Void>) { firstLocationUpdate = true let location = change[NSKeyValueChangeNewKey] as CLLocation mapView.camera = GMSCameraPosition.cameraWithTarget(location.coordinate, zoom: 14) } } 

Je l'ai couru mais il ne pointe pas vers l'endroit que j'ai assigné. Lorsque println() l'location println(mapView.myLocation) , il renvoie nil .

Je suppose que c'est parce que dans iOS8, nous devons explicitement requestr à l'user de nous permettre d'get leur location. Voir ici .

J'ai ajouté la key NSLocationWhenInUseUsageDescription à mon info.plist. Mon problème est comment puis-je requestr l'autorisation sur CLLocationManager depuis que j'utilise SDK Google Maps. J'ai mis le code ci-dessous juste pour vérifier, mais il n'a pas invité la boîte de dialog d'autorisation.

 let locationManager = CLLocationManager() locationManager.requestWhenInUseAuthorization() 

Y a-t-il une solution de contournement? Ou devons-nous attendre que Google met à jour son SDK?

Je vous remercie.

Vous avez besoin que votre CLLocationManager soit conservé, sinon il est libéré avant de pouvoir présenter la boîte de dialog d'autorisation.

 class MapViewController: UIViewController { @IBOutlet var mapView: GMSMapView! var firstLocationUpdate: Bool? let locationManager=CLLocationManager() override func viewDidLoad() { super.viewDidLoad() self.locationManager.requestWhenInUseAuthorization() let camera = GMSCameraPosition.cameraWithLatitude(-33.86, longitude: 151.20, zoom: 12) mapView = GMSMapView.mapWithFrame(CGRectZero, camera: camera) mapView.settings.compassButton = true mapView.settings.myLocationButton = true mapView.addObserver(self, forKeyPath: "myLocation", options: .New, context: nil) dispatch_async(dispatch_get_main_queue(), { () -> Void in self.mapView.myLocationEnabled = true }) println(mapView.myLocation) view = mapView let marker = GMSMarker() marker.position = CLLocationCoordinate2DMake(-33.86, 151.20) marker.title = "Sydney" marker.snippet = "Australia" marker.map = mapView }