从服务器获取坐标后,如何从REST API获取经度和纬度,如何做动态Google标记?
我的 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提取数据后添加标记