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

我试图让用户目前的位置显示与谷歌地图API。 我一直在努力解决这个问题几个星期,代码运行,但没有更新到当前位置,当我在模拟器中更改位置。

我的代码是在下面,看看其他人在做什么,他们都有mapView.myLocationEnabled = true,而对于我这会产生一个错误,说'myLocationEnabled已被重命名为'isMylocationEnabled'。 我见过一些最新的post(从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() } } } 

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

  import UIKit import GoogleMaps class FirstViewController: UIViewController, CLLocationManagerDelegate { @IBOutlet weak var mapView: GMSMapView! var locationManager = CLLocationManager() var vwGMap = GMSMapView() override func viewDidLoad() { super.viewDidLoad() let camera: GMSCameraPosition = GMSCameraPosition.camera(withLatitude: 22.300000, longitude: 70.783300, zoom: 10.0) vwGMap = GMSMapView.map(withFrame: self.view.frame, camera: camera) vwGMap.camera = camera locationManager.delegate = self locationManager.desiredAccuracy = kCLLocationAccuracyKilometer locationManager.distanceFilter = 500 locationManager.requestWhenInUseAuthorization() locationManager.requestAlwaysAuthorization() locationManager.startUpdatingLocation() self.view = vwGMap } func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) { if (status == CLAuthorizationStatus.authorizedWhenInUse) { vwGMap.isMyLocationEnabled = true } } func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { let newLocation = locations.last vwGMap.camera = GMSCameraPosition.camera(withTarget: newLocation!.coordinate, zoom: 15.0) vwGMap.settings.myLocationButton = true self.view = self.vwGMap let marker = GMSMarker() marker.position = CLLocationCoordinate2DMake(newLocation!.coordinate.latitude, newLocation!.coordinate.longitude) marker.map = self.vwGMap } 

}