ios - 将地址快速转换为坐标

标签 ios swift coordinates core-location

如何使用 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/

相关文章:

jquery - 无法使用类设置 div 的高度

ios - 核心数据堆栈: This Apple provided example adds the Persistent Store Coordinator to the stack asynchronously. 为什么?

java - OnTouchListener 坐标不正确

c++ - 在 MATLAB 中迭代坐标矩阵的最佳方法?

php - 地理距离搜索 MYSQL

ios - 我如何了解位置服务是否使用 GPS 来确定用户在 iOS 中的位置?

ios - 带有 CALayer 的 UILabel 阴影不绘制

IOS 10.3.3 不支持 SSL 和 IIS 重写规则

swift - 使用 flutter 的 iPhone XS ideviceinstaller 需要 UDID 验证 - 它不再是 40 位数字并且有破折号

Swift 编译器错误 Int 不可转换为 CGFloat