当前位置:网站首页>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
}
边栏推荐
猜你喜欢
![Summer Challenge [FFH] JS custom component: DIY a keyboard that can be used at any time! (I)](/img/92/abc5c4e7aee3c65aa0f62fc699b4df.jpg)
Summer Challenge [FFH] JS custom component: DIY a keyboard that can be used at any time! (I)

零知识证明:具有DDH假设的 ZKP

My creation anniversary -- July 25th, 2022

Unity 之 切换语言导致报错:System.FormatException:String was not recognized as a valid DateTime.

【实战】用OpenCV实现页面扭曲矫正

Introduction and advanced level of MySQL (10)

Apple develops a complete creation process of Apple certificate and description file

jvm四种引用类型

UE5 GAS 学习笔记0.2配置插件

JVM four reference types
随机推荐
APP为什么用JSON协议与服务端交互:序列化相关知识
Meta Q2财报:营收首次下滑,Metaverse将与苹果竞争
Gateway入门
There is a special cryptology language called asn.1
Golang并发模型之
jvm调优
GO exe生成图标版本信息
Ue5 gas learning notes 8.0 references
Look at Devops construction from SRE
Docker搭建Mysql主从复制
Kotlin:Sealed class密封类详解
MYSQL入门与进阶(三)
1.3、链表
What are the conditions for zero foundation learning software testing?
Experimental building - PHP Dafa
JVM four reference types
MYSQL入门与进阶(五)
Is it really realistic that people who have not been exposed to software testing can take up their posts after two months of training?
LeetCode_ 96_ Different binary search trees
Ue5 gas learning notes 1.2 game Tags