iOS   发布时间:2022-03-30  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ios – CLGeocoder reverseGeocodeLocation返回不同纬度/长度的地标? (附有游乐场示例)大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
为什么CLGeocoder reverseGeocodeLOCATIOn在查找地址时返回具有不同纬度/经度的地标?

背景:对于用户在地图上“长按”以放置引脚,但我的代码反向对此进行地理编码以便能够在引脚上放置区域名称,但随后丢弃的PIn位于不同的位置(即不良好的用户体验).所以我正在寻找一种方法来利用用户实际选择的纬度/经度,但随后只需查找位置名称.

例:使用下面的代码,我看到:

>输入:-28.7780218895614,152.978574011267
>输出:-28.864405,153.0001191

码:

import UIKit
import CoreLOCATIOn
import PlaygroundSupport

// Initial Test Co-ordinate
let Locinput = CLLOCATIOn(latitude: -28.778021889561444,longitude: 152.97857401126666)
print("Input: \(Locinput.coordinate.latitudE),\(Locinput.coordinate.longitudE)")

// Initiate Reverse Geocoding
let geocoder: CLGeocoder = CLGeocoder()
print("About to call reverse geocoding function")
geocoder.reverseGeocodeLOCATIOn(Locinput) { placemarks,error in
    guard let placemarks = placemarks else {fatalError("No Placemarks Provided \(error?.localizedDescription)")}
    for p in placemarks {
        print("OUTPUT:  \(p.LOCATIOn!.coordinate.latitudE),\(p.LOCATIOn!.coordinate.longitudE)")
    }
}

// Enable Asynch
PlaygroundPage.current.needsIndefiniteExecution = true

解决方法

@H_674_21@ 这是正确的行为.地标将返回其相关位置.这显然可能与输入的不同.当您向地理编码器提供位置时,此位置将“推断”您想要获得的地标.

假设这个:

 a: Associated LOCATIOn with the empire state building.
 b: LOCATIOn you provided from an long press for instance.

    -------
    |     |
    |  a  | --> CLPlacemark: Empire state building,LOCATIOn: a
    |    b|
    ------- 

你的假设是正确的.

本图文内容来源于网友网络收集整理提供,作为学习参使用,版权属于原作者。

大佬总结

以上是大佬教程为你收集整理的ios – CLGeocoder reverseGeocodeLocation返回不同纬度/长度的地标? (附有游乐场示例)全部内容,希望文章能够帮你解决ios – CLGeocoder reverseGeocodeLocation返回不同纬度/长度的地标? (附有游乐场示例)所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。