【发布时间】:2017-02-27 11:53:27
【问题描述】:
为什么 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
【问题讨论】:
-
附言。或者在这种情况下的方法是采用 reverseGeocodeLocation 返回的地标并使用位置、子位置、国家字符串,但不是位置/坐标,而是使用“长按”中的坐标?
标签: ios mkmapview clgeocoder reversegeocodelocation