gpt4 book ai didi

swift - 使用 Swift 进行正向地理编码

转载 作者:行者123 更新时间:2023-11-28 16:03:22 24 4
gpt4 key购买 nike

我希望能够让用户输入一个地址,并能够保存该地址,并将其转换为纬度和经度坐标。我没能找到很多关于正向地理编码的文档,而且我在启动这段代码时遇到了问题。我应该要求用户按(城市、州、邮政编码)输入地址吗?还是一个地址就足够了?有没有可以满足我需要的功能?非常感谢任何帮助。

最佳答案

我做了一个简单的 LocationManager github 上的助手,您可以在其中获得想要的东西。

库中有一个函数getReverseGeoCodedLocation。只需将您的地址作为字符串输入,即可获得完整的地标和经纬度。

在你的项目中添加LocationManager.swift文件

如何使用它:-

LocationManager.sharedInstance.getReverseGeoCodedLocation(address: yourAddress, completionHandler: { (location:CLLocation?, placemark:CLPlacemark?, error:NSError?) in

if error != nil {
print((error?.localizedDescription)!)
return
}

if placemark == nil {
print("Location can't be fetched")
return
}

print(placemark?.addressDictionary?.description ?? "")
print((placemark?.location?.coordinate.latitude)!)
print((placemark?.location?.coordinate.longitude)!)

})

在内部它使用 CLGeocodergeocodeAddressString

输出

enter image description here注意:- 它适用于 Swift 3.0 及更高版本

关于swift - 使用 Swift 进行正向地理编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40669667/

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