swift - 从 Rest API 获得响应后添加动态 GoogleMap Marker
问题描述
从服务器获取坐标后如何做动态谷歌标记我从 REST API 获取纬度和经度
我的showMarker函数如下:
private func showMarker(_ lat: String, _ lng: String, _ description: String){
let latitude: CLLocationDegrees = Double(lat) ?? 0.00
let longitude: CLLocationDegrees = Double(lng) ?? 0.00
print("Latitude: \(latitude), Longitude: \(longitude)")
let position = CLLocationCoordinate2DMake(latitude, longitude)
let marker = GMSMarker(position: position)
marker.title = ""
marker.map = self.mapView
}
如果下面的代码在 ViewDidLoad() 中运行正常
self.camera = GMSCameraPosition.camera(withLatitude: 6.244880, longitude: 7.001920, zoom: 10.0)
mapView.camera = self.camera
mapView.animate(toZoom: 10.0)
self.mapView = GMSMapView.map(withFrame: self.view.bounds, camera: self.camera)
但是当我在上面的代码之后在 showMarker 函数之后调用它们时,相机对象得到 nil
我只想在通过rest api获取数据后添加标记
解决方案
推荐阅读
- python - 使用 pygame,如何更新由类定义的对象的位置
- java - 为什么针对 Spanner 模拟器运行的 Spanner spring 演示无法创建池化数据库连接?
- angular - Angular 材质表异步加载数据
- spring-boot - Spring TCP 集成仅每 30+ 秒读取一次
- reactjs - 错误:需要一个赋值或函数调用,而是看到一个表达式 no-unused-expressions。如何解决?
- javascript - 数据表未激活
- laravel - Laravel 与 4 表的关系
- cassandra - 拥有一个带有单行分区的 Cassandra 表是一种不好的做法吗?
- html - 在我添加文本时背景图像与导航栏的距离,我该怎么做?
- powerapps - 如何从 Excel 表格中提取相关数据,在 PowerApps 中创建下拉列表并构建编辑表单?