【问题标题】:Load Map at User Location - Google Maps in iOS在用户位置加载地图 - iOS 中的 Google 地图
【发布时间】:2016-12-11 21:01:24
【问题描述】:

很难让谷歌地图加载用户的位置。

我一直在使用许多资源,尤其是这个,但它最后一次更新是一年多前,在 Swift 3 / Xcode 8 中效果不佳 (https://www.raywenderlich.com/109888/google-maps-ios-sdk-tutorial

谁有一些示例代码或调整可以帮助我完成此任务?

RayWenderlich 教程的主要问题 - 不允许我运行扩展程序中的函数。扩展中导入的类是多余的并抛出错误。没有这些类,您将无法使用扩展。因此,我尝试仅使用一个函数,但尝试调用时出现错误 func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus 状态: CLAuthorizationStatus)

【问题讨论】:

  • 尝试获取用户位置,然后在启动时使用它来设置地图位置。因此,地图应该以中心的用户位置加载。

标签: google-maps swift3 xcode8


【解决方案1】:

已解决:

变量

var centerMap = true

ViewDidLoad

super.viewDidLoad()
    self.locationManager.delegate = self
    locationManager.desiredAccuracy = kCLLocationAccuracyBest
    locationManager.requestWhenInUseAuthorization()
    if CLLocationManager.locationServicesEnabled() {
        self.locationManager.startUpdatingLocation()
        self.mapView?.isMyLocationEnabled = true
        print("locationserviceson")
        centerMap = true

用户位置变化时更新的功能

func locationManager(_ manager: CLLocationManager, didUpdateLocations location: [CLLocation]) {
    print("yes")

    userLocation = location.last!
    if centerMap == true {
        self.mapView.camera = GMSCameraPosition.camera(withTarget: userLocation.coordinate, zoom: 15.0)
        self.locationManager.stopUpdatingLocation()
        centerMap == false
    }

}

【讨论】:

    猜你喜欢
    • 2015-05-04
    • 1970-01-01
    • 1970-01-01
    • 2023-02-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-16
    相关资源
    最近更新 更多