gpt4 book ai didi

swift - 在ios swift4中通过纬度和经度创建 map 图像

转载 作者:搜寻专家 更新时间:2023-11-01 06:26:02 25 4
gpt4 key购买 nike

通过 API,我有特定位置的纬度和经度,需要在 ImageView 上以 map 形式显示这些坐标。我想通过这些坐标绘制 map View 图像。想要显示特定位置以及经纬度。我怎样才能做到?

最佳答案

func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {

if locationUpdate == false {
locationUpdate = true
guard let locValue: CLLocationCoordinate2D = manager.location?.coordinate else { return }
print("locations = \(locValue.latitude) \(locValue.longitude)")
var latStr = ""
var longStr = ""
latStr = String(locValue.latitude)
longStr = String(locValue.longitude)

let staticMapUrl = "http://maps.google.com/maps/api/staticmap?markers=color:blue|\(latStr),\(longStr)&\("zoom=10&size=400x300")&sensor=true&key=AIzaSyBXAdCe4nJuapECudMeh4q-gGlU-yAMQX0"

print(staticMapUrl)

let url = URL(string: staticMapUrl.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!)

do {
let data = try NSData(contentsOf: url!, options: NSData.ReadingOptions())
imgLocationOnMap.image = UIImage(data: data as Data)
} catch {
imgLocationOnMap.image = UIImage()
}


}
}

关于swift - 在ios swift4中通过纬度和经度创建 map 图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54568639/

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