如何使用 Swift 将 String
地址转换为 CLLocation
坐标?
我还没有代码;我寻找解决方案,但找不到任何解决方案。
最佳答案
使用CLGeocoder
将地址反向地理编码为纬度/经度坐标:
let address = "1 Infinite Loop, Cupertino, CA 95014"
let geoCoder = CLGeocoder()
geoCoder.geocodeAddressString(address) { (placemarks, error) in
guard
let placemarks = placemarks,
let location = placemarks.first?.location
else {
// handle no location found
return
}
// Use your location
}
您还需要添加和导入 CoreLocation 框架。
关于ios - 将地址快速转换为坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42279252/