如何在iOS app + Swift中控制googlemap的大小?

时间:2017-06-29 22:50:21

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

我正在尝试构建一个使用googleMaps API的iOS应用。到目前为止,我做了很多工作,但我遇到了一个问题,即“我无法控制应用程序中显示的地图大小”。它总是需要全屏。显然,我错过了一些东西。

以下是我的代码的快照:

        locationManager.desiredAccuracy = kCLLocationAccuracyBest
        locationManager.requestAlwaysAuthorization()
        locationManager.startUpdatingLocation()
        locationManager.delegate =  self

        /// Google maps stuff
        let camera = GMSCameraPosition.camera(withLatitude:-33.8688,longitude: 151.2093, zoom: 13.0)
        self.mapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera)
        self.mapView.isMyLocationEnabled = true
        /// Google maps stuff

大多数解决方案都是关于添加UIView(UIView = myView) 然后使用这个视图:

self.myView = mapView 

self.myView = self.mapView 

他们没跟我合作:(

1 个答案:

答案 0 :(得分:5)

let camera = GMSCameraPosition.camera(withLatitude: coordinates.latitude,longitude:coordinates.longitude, zoom:15)
let mapView = GMSMapView.map(withFrame: CGRect(x: 0, y: 64, width: self.view.frame.size.width, height: self.view.frame.size.height), camera: camera)
DispatchQueue.main.async(execute: {
    mapView.animate(toLocation: coordinates)
    UIView.animate(withDuration: 0.4, animations: {
        mapView.layoutIfNeeded()
    })
})

mapView.isMyLocationEnabled = true
let marker = GMSMarker()
marker.position = camera.target
mapView.isUserInteractionEnabled = true
marker.title = "\(self.strLabelHeading)!"
marker.map = mapView
self.viewMap.addSubview(mapView)