ios - Google Maps Mapview 不以标记为中心
问题描述
我在 ios 中使用带有 swift 4 的谷歌地图,我必须在屏幕上显示一个带有标记的地图视图,问题是每当我显示地图视图时,我都会得到这个结果:
我想要得到的结果是这样的:
这是我正在使用的代码:
func loadMap(location:CLLocation){
self.mapView.isMyLocationEnabled = true
self.mapView.isUserInteractionEnabled = true
self.view.layoutIfNeeded()
self.addLocationMarker()
}
func addLocationMarker(){
// Creates a marker in the center of the map.
let marker = GMSMarker()
print(self.startLocation)
marker.position = CLLocationCoordinate2D(latitude: self.startLocation.coordinate.latitude, longitude: self.startLocation.coordinate.longitude)
marker.map = self.mapView
let camera = GMSCameraPosition.camera(withLatitude: self.startLocation.coordinate.latitude, longitude: self.startLocation.coordinate.longitude, zoom: 12.0)
self.mapView.camera = camera
}
mapview 是情节提要中视图的出口
解决方案
这段代码对我来说很好。试试这个(Swift 4)
func setupMapView() {
DispatchQueue.main.async {
let position = CLLocationCoordinate2D(latitude: 32.9483364, longitude: -96.8241543)
let marker = GMSMarker(position: position)
self.mapView.camera = GMSCameraPosition(target: position, zoom: 15, bearing: 0, viewingAngle: 0)
marker.title = "Enter marker title here"
marker.map = self.mapView
}
}
注意:我使用了样本经度和纬度。你应该插入你的。
推荐阅读
- amazon-web-services - Terraform RDS:由于修改而破坏后恢复数据?
- javascript - MutationObserver 没有检测到 querySelectorAll()[] 内部的变化
- java - SimpleDateFormat 解析方法第一次工作,第二次被忽略
- mysql - 从两个表具有不同条件的 2 个表中获取值
- javascript - 访问值是否在对象内
- php - Wordpress Rest API - 检索标头授权凭据并传递我自己的成功或失败
- reactjs - Google 图书 API:在特定搜索中“无法读取未定义的属性‘缩略图’”
- reactjs - 用于回调的新 React 钩子
- python - Python Parser-尝试为特殊字符串处理 400 MB 文件。我看到以下代码在文件较小时有效
- python - 如何存储所有 python 按键 RT 而不仅仅是第一个?