ios - 如何在 iOS 应用程序 + Swift 中控制 googlemap 的大小?

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

我正在尝试构建一个使用 googleMaps API 的 iOS 应用程序。到目前为止,我的工作做得很好,但我遇到了一个问题,即“我无法控制应用程序中显示的 map 的大小”。它总是需要全屏。显然,我遗漏了什么。

这是我的代码的快照:

        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 ) 然后像这样使用这个 View :

self.myView = mapView 

self.myView = self.mapView 

他们没有和我一起工作:(

最佳答案

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)

关于ios - 如何在 iOS 应用程序 + Swift 中控制 googlemap 的大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44836133/

相关文章:

iphone - iPhone:单个开发人员是否需要临时配置?

ios - 单击 Swift 4 中的自定义按钮时调整单元格大小

ios - 无后端查询的空 TableView 结果,如何填充到表中

ios - 如何以编程方式获取正确的 iOS 版本?

ios - UIView 和 UIButton 上的 UIView 不起作用

iphone - iOS Gamekit 最大点对点大小

iphone - Objective-C 动态对象创建内存问题

swift - 无法使用 MLModel.compileModel 加载 CoreML 模型(位于 :)

ios - 如果计数等于 0,如何将显示数据从 API 跳过到 Collection View 单元格

iphone - TableView 滚动异步