在Google地图中移动相机

时间:2016-09-12 12:46:49

标签: ios swift google-maps google-maps-sdk-ios

我正在尝试将Google地图中的相机移动到指定位置(lat& long)。

这是我的代码/函数,这段代码位于ViewController1(包含mapView的视图)中:

func select_structure(lat: String, lon: String){

        let camera = GMSCameraPosition.cameraWithLatitude(Double(lat)!, longitude: Double(lon)!, zoom: 6.0)
        mapView = GMSMapView.mapWithFrame(CGRect.zero, camera: camera)
        mapView.myLocationEnabled = true
        mapView.mapType = kGMSTypeSatellite
        mapView.camera = camera

        view = mapView

        populate_structures2()

        let newcamera = GMSCameraPosition.cameraWithLatitude(Double(lat)!, longitude: Double(lon)!, zoom: 17.0)

        self.mapView.animateToCameraPosition(newcamera)
        print(mapView)

    }

当我在ViewController2中调用该代码时,当应用程序第一次运行时,它不起作用。当我使用该功能时没有任何反应。但我知道它正在阅读中。当我运行第二个,第三个等等时,它就可以了!

快速说明一下。 ViewController2是一个滑动菜单。我通过ViewController1调用函数:

var ClassViewController = self.storyboard!.instantiateViewControllerWithIdentifier("ViewController") as! ViewController
        ClassViewController.select_structure(structures_lat[indexPath.item], lon: structures_lon[indexPath.item])

我在ViewController1的loadView中初始化mapView:

 override func loadView() {

            let camera = GMSCameraPosition.cameraWithLatitude(35.98917593, longitude: -95.94740106, zoom: 6.0)
            mapView = GMSMapView.mapWithFrame(CGRect.zero, camera: camera)
            mapView.myLocationEnabled = true
            mapView.mapType = kGMSTypeSatellite
            //mapView.delegate = self
            mapView.settings.allowScrollGesturesDuringRotateOrZoom = false
            view = mapView
            load_lines()
            load_structures()
    }

有什么想法吗?

0 个答案:

没有答案