本文介绍了将地址转换为swift坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将 String 地址转换为 CLLocation 与Swift的坐标?我还没有代码,我找了一个解决方案,但我还没找到任何人。

How can I convert a String address to CLLocation coordinates with Swift? I have no code yet, I looked for a solution but I didn't find anyone yet.

谢谢。

推荐答案

这很简单。

    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框架。

You will also need to add and import CoreLocation framework.

这篇关于将地址转换为swift坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 06:53