使用GoogleMaps时,myLocationEnabled在swift上更改为isMyLocationEnabled

时间:2016-11-24 17:56:50

标签: ios swift google-maps rename currentlocation

我试图让用户使用google maps API显示当前位置。几个星期以来我一直在努力解决这个问题并且代码运行但是当我更改模拟器中的位置时,它不会更新到当前位置。

我的代码在下面,在查看其他人如何操作后,他们都有mapView.myLocationEnabled = true,而对我来说,这会产生一个错误,说'myLocationEnabled已被重命名为'isMylocationEnabled'。我已经看到一些最新的帖子(从2个月前开始),每个人都在使用myLocationEnabled,似乎没有错误,为什么我得到这个?这可能是我当前位置没有更新的原因吗?

import UIKit
import GoogleMaps

class FirstViewController: UIViewController, CLLocationManagerDelegate {


    @IBOutlet weak var mapView: GMSMapView!


    let locationManager = CLLocationManager()
    override func viewDidLoad() {
        super.viewDidLoad()
        locationManager.delegate = self
        mapView.settings.myLocationButton = true
        mapView.settings.compassButton = true
    }
    override func viewDidAppear(_ animated: Bool) {
        locationManager.requestWhenInUseAuthorization()
    }
    func locationManager(manager: CLLocationManager , didChangeAuthorizationStatus status: CLAuthorizationStatus) {
        if status == .authorizedWhenInUse {
            locationManager.startUpdatingLocation()


            mapView.isMyLocationEnabled = true

            mapView.settings.myLocationButton = true
        }
    }
    func locationManager(manager: CLLocationManager ,didUpdateLocations locations: [CLLocation]) {
        if let location = locations.first {

            mapView.camera = GMSCameraPosition(target: location.coordinate, zoom: 15, bearing: 0, viewingAngle: 0)

            let marker = GMSMarker()
            marker.title = "Current Location"
            marker.map = mapView
            locationManager.stopUpdatingLocation()
        }
    }
}

1 个答案:

答案 0 :(得分:1)

所以我最终解决了这个问题!基本上我用GoogleMaps和GooglePlaces更新了现有的Podfile,然后更新了pod以确保所有框架都正常工作。然后我用这段代码让我当前的位置工作

{{1}}

}