【问题标题】:CLGeocoder reverseGeocodeLocation is returning placemark with different lat/long? (playground example attached)CLGeocoder reverseGeocodeLocation 返回具有不同纬度/经度的地标? (附游乐场示例)
【发布时间】: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


【解决方案1】:

这是正确的行为。地标将返回它的关联位置。这显然可能与输入不同。当您向地理编码器提供位置时,该位置将“推断”您想要获取的地标。

假设:

a:与帝国大厦相关的位置。 b:例如,您通过长按提供的位置。 -------- | | |一个 | --> CLPlacemark:帝国大厦,位置:a |乙| --------

您的假设是正确的。 :)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-08-21
    • 1970-01-01
    • 2016-07-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-18
    相关资源
    最近更新 更多