谷歌地图无法缩放到我当前的位置



我必须在谷歌地图视图中绘制多个图钉,然后缩放到用户的当前位置。图钉已成功绘制,但未缩放到当前位置。任何帮助将不胜感激

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
}
}

您的缩放设置为 0,请像波纹管一样将其增加到 15/16。

let camera  = GMSCameraPosition.camera(withLatitude: lat, longitude: lon, zoom: 16)

相关内容

  • 没有找到相关文章

最新更新