【问题标题】:Google maps - Update User location谷歌地图 - 更新用户位置
【发布时间】:2018-04-21 12:34:50
【问题描述】:

我正在使用适用于 iOS 的 Google 地图 SDK。 isMyLocationEnabled 设置为 true。

有时使用位置会更新到正确的位置。但有时位置不会更新。 我想知道这个选项是否使用用户的原始坐标?另外,还有更新用户位置的选项吗? ) 我说的是蓝点。

【问题讨论】:

    标签: ios google-maps google-maps-sdk-ios


    【解决方案1】:

    这可能会有所帮助:

    import Foundation
    import CoreLocation
    
    class Location: NSObject {
    
      static let shared = Location()
      var locationManager = CLLocationManager()
    
      func locationManagerSetup() {
        // Ask for Authorisation from the User.
        locationManager.requestAlwaysAuthorization()
    
        // If location services is enabled get the users location
        if CLLocationManager.locationServicesEnabled() {
          locationManager.delegate = self
          locationManager.desiredAccuracy = kCLLocationAccuracyBest
          locationManager.requestLocation()
          locationManager.startUpdatigLocation()
        }
    
      }
    
    }
    
    extension Location: CLLocationManagerDelegate {
    
      func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
        if let location = locations.first {
          // do something
          manager.stopUpdatingLocation()
        }
        else {
          manager.requestLocation()
        }
      }
    
      func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
        manager.requestLocation()
      }
    
      // If we have been deined access give the user the option to change it
      func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
        if(status == CLAuthorizationStatus.denied) {
          // do something
        }
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-24
      • 1970-01-01
      • 2015-10-18
      相关资源
      最近更新 更多