I\'m trying to use the Google Maps for iOS in a Swift project for iOS 8. I added the Objective-C bridging header and added the Google Maps SDK as instructed in their documen
You need your CLLocationManager to be retained, otherwise it is released before it gets a chance to present the authorisation dialog.
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
}