Google地图不会缩放到我当前的位置

时间:2017-07-30 04:24:36

标签: ios swift google-maps swift3

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

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

1 个答案:

答案 0 :(得分:0)

您的变焦设置为0,如下所示将其增加到15/16。

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