4
为什么CLGeocoder reverseGeocodeLocation在查找地址时返回具有不同纬度/经度的地标?CLGeocoder reverseGeocodeLocation是不同的纬度/经度的返回地标? (附带操场示例)
背景:在地图上用户“长按”放置一个引脚,但我的代码反向地理编码,这是为了能够在Pin上放置一个区域名称,但是然后丢弃的PIN是不同的位置(即不是一个好的用户体验)。所以我正在寻找一种方法来利用用户实际选择的lat/long,然后查找位置名称。
例如:采用下面的代码我看到:
- 输入:-28.7780218895614,152.978574011267
- OUTPUT:-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
PS。或者在这种情况下,采用由reverseGeocodeLocation返回的地标,并使用地点,子地点,国家字符串,但不是位置/坐标,而是使用“长按”的坐标? – Greg