我无法将当前位置添加到Google地图

时间:2016-06-07 09:35:32

标签: swift google-maps currentlocation

import UIKit
import GoogleMaps
import CoreLocation

class ViewController: UIViewController {

    let locationManager = CLLocationManager()
    var mapView: GMSMapView?


    override func viewDidLoad() {
        super.viewDidLoad()

        GMSServices.provideAPIKey("XYZ")

        let camera = GMSCameraPosition.cameraWithLatitude(37.621262,longitude: -122.378945, zoom: 12)
        mapView = GMSMapView.mapWithFrame(CGRectZero, camera: camera)
        view = mapView

    }
}

我应该在此代码中添加什么内容?

1 个答案:

答案 0 :(得分:0)

这应该对你有帮助,请检查。

import UIKit
import GoogleMaps
import CoreLocation

class ViewController: UIViewController {

    let locationManager = CLLocationManager()
    var mapView: GMSMapView?


    override func viewDidLoad()
    {
        super.viewDidLoad()
        GMSServices.provideAPIKey("XYZ")
        let camera = GMSCameraPosition.camera(withLatitude: 37.621262,longitude: -122.378945, zoom: 12)
        mapView = GMSMapView.map(withFrame: CGRect.init(), camera: camera)
        // Below line is to default show user current location(Bue dot with circular accuracy radius around it)
        mapView!.isMyLocationEnabled = true
        view = mapView
    }
}

希望有所帮助。