gpt4 book ai didi

swift - 具有多个标记的 map 在放入调度队列时列表中有多个标记时仅显示一个标记

转载 作者:行者123 更新时间:2023-11-28 07:34:11 25 4
gpt4 key购买 nike

我有一个经纬度数组,我试图将所有带标记的经纬度放在 map 上,只有 1 个标记出现。请帮忙

for item in json {
//print(item["price"])
if let vendor = item["vendor"] as? [String:Any],
let lat = vendor["latitude"] as? Double,
let lon = vendor["longitude"] as? Double,
let termsandcondi = item["termsAndConditions"] as? String,
let pre = item["price"] as? Int ,
let name = item["name"] as? String, !name.isEmpty {
//print(termsandcondi)
//print(pre)
self.locationManager.delegate = self
self.locationManager.requestWhenInUseAuthorization()
self.locationManager.startUpdatingLocation()
let data = ["name":name,"latitude":lat,"longitude":lon,"termsAndConditions":termsandcondi,"price":pre] as! [String : AnyObject]
//print("getting here")
self.myArray.append(data)
DispatchQueue.main.async {
print("Coming here !! Dispatch Queue")
let camera = GMSCameraPosition.camera(withLatitude:12.9716, longitude:77.5946, zoom: 10.0)
let subView = GMSMapView.map(withFrame: CGRect(x: 0, y: 0, width: self.mapView.frame.size.width, height: self.mapView.frame.size.height), camera: camera)
self.nameDeal.text = name as String?
self.pric.text = String(describing: pre)
let marker = GMSMarker()
marker.position = CLLocationCoordinate2D(latitude:lat, longitude:lon)
marker.title = name
marker.map = self.mapView
//marker.map = self.mapView
}

最佳答案

此方法将使您在 map 上发布多个图钉。把它放在一个方法中并使用函数 preparingMap(){

//Filtered data is in array of key values that contains lat long
guard let _filteredData = filteredData else { return }

//Converting lat long to double
var latitude = filteredData?.first?.lATITUDE
var longitude = filteredData?.first?.lONGITUDE


for pins in _filteredData{
let position = CLLocationCoordinate2D(latitude: CLLocationDegrees(Float(latitude)), longitude: CLLocationDegrees(Float(longitude)))
let marker = GMSMarker(position: position)
marker.icon = UIImage(named: "map-location-pin")
marker.map = self.mapView
marker.userData = pins.iD
}
}

关于swift - 具有多个标记的 map 在放入调度队列时列表中有多个标记时仅显示一个标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53736602/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com