为什么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
解决方法
这是正确的行为.地标将返回其相关位置.这显然可能与输入的不同.当您向地理编码器提供位置时,此位置将“推断”您想要获得的地标.
假设这个:
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| -------
你的假设是正确的.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。