ios - Google map 无法缩放到我当前的位置

标签 ios swift google-maps swift3

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

 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)

关于ios - Google map 无法缩放到我当前的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45396353/

相关文章:

javascript - 刷新网页时保持缩放

iphone - 如何调整 UIImage 的大小?

ios - 每次应用程序注册时都会调用 didRegisterForRemoteNotificationsWithDeviceToken 吗?

ios - 快速访问 UIButton 的文本时出现奇怪的错误

ios - 使用异步编程在 TableView 上显示事件指示器 - Swift

swift - 快速解析用户代理

iphone - 旋转父 View 后计算 CGAffineTransform 矩阵

Swift dispatch_async 导致 EXC_BAD_ACCESS 错误

android - 如何缩放相机以覆盖android googlemap中的路径?

javascript - 每 X 秒使用 mysql 数据更新 google java map