In my project I use LocationSearchTable
/ MKLocalSearch
. When a user clicks on an item, my add annotation method is called in MapViewController
:
func dropPinZoomIn(placemark: MKPlacemark) {
// cache the pin
selectedPin = placemark
// create the pin
let annotation = MKPointAnnotation()
annotation.coordinate = placemark.coordinate
annotation.title = placemark.name
if let streetNumber = placemark.subThoroughfare,
let city = placemark.locality,
let state = placemark.administrativeArea {
annotation.subtitle = "\(streetNumber) \(city) \(state)"
}
// add the pin the the mapView
mapView.addAnnotation(annotation)
let span = MKCoordinateSpanMake(0.01, 0.01)
let region = MKCoordinateRegionMake(annotation.coordinate, span)
mapView.setRegion(region, animated: true)
print(placemark.coordinate)
print(placemark.coordinate.latitude)
print(placemark.coordinate.longitude)
At the end, when I print the coordinate, I get a longer version whereas when I print the latitude and longitude separately, it rounds off the number near the end. This is causing me troubles later when I need to compare coordinates. How can I prevent this rounding? As an example, here are my results:
CLLocationCoordinate2D(latitude: 37.331413259110334, longitude: -122.03048408031462) CLLocationCoordinate2D(latitude: 37.3314132591103, . . longitude: -122.030484080315)