当前位置:网站首页>SwiftUI Swift 之正向地理编码与反向地理编码(教程含源码)
SwiftUI Swift 之正向地理编码与反向地理编码(教程含源码)
2022-07-28 17:07:00 【知识大胖】
您有没有想过地图服务如何在不知道其坐标的情况下找到您提供的确切地址?在本文中,我将向您介绍地理编码,这是获取有关地理位置的信息的过程。地理编码可以有两种方式。
正向地理编码——这是我们从邮政地址或位置开始(例如:波士顿,马萨诸塞州)并将其转换为一组相应的地理坐标(纬度和经度)
反向地理编码——这是当我们通过给定的纬度、经度作为输入来获取地址或位置时
在本教程中,我将使用Apple Maps和Google Maps对地址进行地理编码。在开始之前,我们将参考的文档可以在这里找到:Google Maps Geocoding API | 苹果地图地理编码。
虽然 Apple 使用CLGeocoder类调用其正向或反向地理编码方法之一,但谷歌地图使用外部 URL 来启动服务。
让我们从 Apple 地理编码开始吧!
让我们创建一个新的 Xcode 项目。在开始使用CLGeocoder类之前,将Core Location框架添加到项目中。在ViewController的顶部,导入Core Location框架并为 Apple Maps 中的前向地理编码创建一个新方法。
func forwardGeocoding(address: String) {
let geocoder = CLGeocoder()
geocoder.geocodeAddressString(address, completionHandler: { (placemarks, error) in
if error != nil {
print("Failed to retrieve location")
return
}
边栏推荐
- UE5 GAS 学习笔记8.0参考资料
- Attention mechanism and code implementation
- leetcode 二叉树类
- jvm调优
- Introduction and advanced level of MySQL (10)
- 2022-07-27 study notes of group 4 self-cultivation class (every day)
- [actual combat] realize page distortion correction with OpenCV
- LeetCode_63_不同路径Ⅱ
- UE5 GAS 学习笔记 1.3属性Attribute
- What is the employment prospect of software testing?
猜你喜欢
随机推荐
What are the conditions for zero foundation learning software testing?
Experimental building - PHP Dafa
1.2 queue
Mingde biology: no products of the company have been listed in the WHO recommended list
Ue5 gas learning notes 1.1 capability system component
2022.7.26 构造函数,面试:new的作用、深拷贝和浅拷贝
Wired: who owns the art of the future? Openai allows dall-e users to commercialize their works. At present
Zero knowledge proof: zkp with DDH assumption
What if you don't understand the difference between modularity, componentization and plug-in?
408复习策略(强化阶段)
112. 使用自开发的代理服务器解决 SAP UI5 FileUploader 上传文件时遇到的跨域访问错误
LeetCode_ 63_ Different paths II
What kind of knowledge payment system functions are more conducive to the development of the platform and lecturers?
苹果开发完整的苹果证书与描述文件创建流程
MySQL index usage and optimization
Is it difficult for novices to change careers through self-study software testing?
2022-07-27 study notes of group 4 self-cultivation class (every day)
面试官:ThreadLocal使用场景有哪些?内存泄露问题如何避免?
记录自己在厦门两年来的面试经历--完结篇
Ue5 gas learning notes 1.7 task ability tasks









![[actual combat] realize page distortion correction with OpenCV](/img/7b/7e25bde34a9d5463af3dd40599c80e.png)