Does CLGeocoder reverseGeocodeLocation return a label with different lat / long? (attached example of a playground)

Why does CLGeocoder reverseGeocodeLocation return a label with a different lat / long when it looks at the address?

Reference Information. As for the user, a “long press” on the map to remove the pin, but my code will reverse geocode to be able to name the area name on the Pin, but then the reset PIN is in a different place (i.e. not a very good user interface ) Therefore, I am looking for a way to use lat / long selected by the user, but then just find the location name.

Example: with the code below I see:

  • Entrance: -28.7780218895614, 152.978574011267
  • EXIT: -28.864405, 153.0001191

the code:

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
+4
1

. . , , . , "" , .

:

 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|
    ------- 

.:)

+1

Source: https://habr.com/ru/post/1670922/


All Articles