0
我必須在Google Map視圖中繪製多個針腳,然後縮放到用戶的當前位置。引腳已成功繪製,但未縮放到當前位置。任何幫助,將不勝感激谷歌地圖不縮放到我目前的位置
override func viewDidAppear(_ animated: Bool) {
if (self.googleMapsView == nil) {
self.googleMapsView = GMSMapView(frame: self.mapViewContainer.frame)
self.view.addSubview(self.googleMapsView)
print(AppDelegate.getAppDelegate().mapArray)
googleMapsView.clear()
for i in 0...AppDelegate.getAppDelegate().mapArray.count - 1 {
let lon = Double ((AppDelegate.getAppDelegate().mapArray[i]["lon"] as? String)!)
let lat = Double ((AppDelegate.getAppDelegate().mapArray[i]["lat"] as? String)!)
let tit = AppDelegate.getAppDelegate().mapArray[i]["location"] as? String
locateWithLongitude(lon: lon!,andLatitude: lat! ,andTitle: tit!)
}
let marker = GMSMarker(position: AppDelegate.getAppDelegate().myLocation)
let camera = GMSCameraPosition.camera(withLatitude: AppDelegate.getAppDelegate().myLocation.latitude, longitude: AppDelegate.getAppDelegate().myLocation.longitude, zoom: 11)
self.googleMapsView.camera = camera
marker.title = AppDelegate.getAppDelegate().sublocality
marker.map = self.googleMapsView
self.googleMapsView.animate(to: camera)
}
}
func locateWithLongitude(lon: Double, andLatitude lat: Double, andTitle title: String) {
DispatchQueue.main.async() {() -> Void in
let position = CLLocationCoordinate2DMake(lat, lon)
let marker = GMSMarker(position: position)
let camera = GMSCameraPosition.camera(withLatitude: lat, longitude: lon, zoom: 0)
self.googleMapsView.camera = camera
marker.title = title
marker.map = self.googleMapsView
}
}
你能解釋一下你在做什麼?因爲你可以多次調用放大縮小,因爲我可以看到,如果你可以解釋一點,我們可以更容易地幫你 –
我已經在地圖上繪製了多個註解並縮放到當前位置 –
你只需要縮放到當前位置或幾個地點在一個又一個? –