我有一個應用程序需要不斷更新用戶位置,以便我可以顯示其當前座標和高度。我使用的didUpdateLocations功能這樣做:谷歌地圖iOS SDK每個位置更新後防止攝像頭縮放
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
if let location = locations.last {
mapView.camera = GMSCameraPosition(target: locationManager.location!.coordinate, zoom: 15, bearing: 0, viewingAngle: 0)
let locValue : CLLocationCoordinate2D = manager.location!.coordinate
let altitude : CLLocationDistance = Double(round(1000*manager.location!.altitude)/1000)
let long = Double(round(10000*locValue.longitude)/10000)
let lat = Double(round(10000*locValue.latitude)/10000)
let alt = String(altitude) + " m"
latitudeLabel.text = String(lat)
longitudeLabel.text = String(long)
altitudeLabel.text = alt
showLearningObjectsWithinRange(location)
}
}
的問題是,當我嘗試放大地圖上的某一點,如果我移動設備甚至略有鏡頭拉近回來了一次。很顯然,這是因爲我的didUpdateLocations函數中的第一行設置了攝像頭位置,但是如果我刪除該線,地圖根本不會居中它們的位置。
我試着將GMSCameraPosition代碼移動到viewDidLoad,viewWillAppear和其他幾個地方,但是這導致應用程序崩潰,因爲它無法及時找到用戶。
有沒有人有關於如何使這項工作的任何建議?謝謝。
變焦這一點:15,使用map.camera.zoom東西或文檔檢查,使得變焦並沒有改變當你更新位置 – Shubhank