Ios 使用谷歌地图时,myLocationEnabled在swift上更改为isMyLocationEnabled

Ios 使用谷歌地图时,myLocationEnabled在swift上更改为isMyLocationEnabled,ios,swift,google-maps,rename,currentlocation,Ios,Swift,Google Maps,Rename,Currentlocation,我正试图用谷歌地图API向用户显示当前位置。我已经为这个问题挣扎了好几个星期,代码运行了,但是当我在模拟器中更改位置时,代码没有更新到当前位置 下面是我的代码,在查看其他人的操作方式后,他们都有mapView.myLocationEnabled=true,而对于我来说,这会产生一个错误,即“myLocationEnabled已重命名为”isMylocationEnabled“。我看到了一些最新的帖子(从2个月前开始),每个人都在使用myLocationEnabled,没有错误。看起来,为什么我会

我正试图用谷歌地图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()
        }
    }
}

所以我终于解决了这个问题!基本上,我用GoogleMaps和GooglePlaces更新了我现有的pod文件,然后更新了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
    }

}

您是否在google开发者控制台中创建了一个项目?顺便说一句,你应该要么更新你的旧帖子,要么删除它,而不是创建一个有相同问题的新帖子。这也会有帮助的。嘿,是的,我有。我的代理中有我的API密钥,谷歌地图确实显示了,只是没有显示当前位置。好的,很抱歉,我会删除旧帖子。这实际上是我最初遵循的教程,但没有迹象表明他有同样的问题。我还尝试了本教程和我在网上找到的其他教程。顺便问一下,“isMyLocationEnabled”是一个BOOL-这可能是问题所在吗?这可能是一个框架的问题吗?因为我手动下载了谷歌地图SDK,所以可能遗漏了什么?