为什么 CLGeocoder reverseGeocodeLocation 在查找地址时返回具有不同纬度/经度的地标?
背景:就用户在 map 上“长按”以放置图钉而言,但我的代码对此进行了反向地理编码,以便能够在图钉上放置区域名称,但随后放置的图钉位于不同的位置(即不好的用户体验)。所以我正在寻找一种方法来利用用户实际选择的纬度/经度,但随后只需查找位置名称。
示例:我看到下面的代码:
代码:
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/