gpt4 book ai didi

ios - CLGeocoder reverseGeocodeLocation 返回具有不同纬度/经度的地标? (附 Playground 示例)

转载 作者:可可西里 更新时间:2023-11-01 06:02:02 31 4
gpt4 key购买 nike

为什么 CLGeocoder reverseGeocodeLocation 在查找地址时返回具有不同纬度/经度的地标?

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

示例:我看到下面的代码:

  • 输入:-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

最佳答案

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

假设这样:

 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 返回具有不同纬度/经度的地标? (附 Playground 示例),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42485146/

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