使用 swift 4.1 在谷歌地图上不显示多个标记我正在连接 JSON 并在控制台上显示结果,但是如何使用谷歌地图连接纬度和经度。
let jsonUrl = URL(string: "http://assetlinkasia.no-ip.biz:8001/hf_tracker/api/userdevices.php?accesskey=12345&user_id=1")
if let url = jsonUrl {
let data = NSData(contentsOf: url)
if let data = data {
do{
let jsonObject = try JSONSerialization.jsonObject(with: data as Data, options: .allowFragments)
if let object = jsonObject as? [NSString: AnyObject]{
if let allDevices = object["data"] as? [[NSString: AnyObject]]{
print("Successfull")
print(allDevices)
}
}
}catch{
print("Error Eccurred")
}
}
}
这是我的谷歌地图代码:
let getLongijson = Double("67.0011")
let getlatijson = Double("24.8607")
let camera = GMSCameraPosition.camera(withLatitude: getlatijson!, longitude: getLongijson!, zoom: 13.0)
let mapView = GMSMapView.map(withFrame: view.bounds, camera: camera)
self.view = mapView
// meanView.addSubview(mapView)
let marker = GMSMarker()
marker.position = CLLocationCoordinate2D(latitude: getlatijson!, longitude: getLongijson!)
marker.infoWindowAnchor = CGPoint(x:0.10, y:0.10)
marker.title = HeadingName
marker.snippet = Countory
marker.icon = UIImage(named: "markers")
marker.map = mapView
//User Location
locationManager.delegate = self
locationManager.requestWhenInUseAuthorization()
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.startUpdatingLocation()
// self.menuFunction()
mapView.delegate = self