【发布时间】:2018-02-27 15:27:29
【问题描述】:
在我的项目中,我使用LocationSearchTable / MKLocalSearch。当用户点击一个item时,我的add注解方法在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)
最后,当我打印坐标时,我会得到一个更长的版本,而当我分别打印纬度和经度时,它会将接近末尾的数字四舍五入。当我需要比较坐标时,这给我带来了麻烦。我怎样才能防止这种舍入?例如,这是我的结果:
CLLocationCoordinate2D(纬度:37.331413259110334,经度:-122.03048408031462) CLLocationCoordinate2D(纬度:37.3314132591103,...经度:-122.030484080315)
【问题讨论】:
标签: ios swift annotations mapkit coordinates