我正在尝试构建一个使用 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/