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