我在使用Swift 3.0的iOS应用程序中使用Google PlacePicker API。 小数点后我需要13位精度。但Google PlacePicker在小数点后返回7位数的纬度和经度。
以下是我的功能:
func pickPlace(sender: UIButton) {
let center = CLLocationCoordinate2D(latitude: (locationManager.location?.coordinate.latitude)!, longitude: (locationManager.location?.coordinate.longitude)!)
let northEast = CLLocationCoordinate2D(latitude: center.latitude + 0.001, longitude: center.longitude + 0.001)
let southWest = CLLocationCoordinate2D(latitude: center.latitude - 0.001, longitude: center.longitude - 0.001)
let viewport = GMSCoordinateBounds(coordinate: northEast, coordinate: southWest)
let config = GMSPlacePickerConfig(viewport: viewport)
let placePicker = GMSPlacePicker(config: config)
placePicker.pickPlace(callback: {(place, error) -> Void in
if let error = error {
print("Pick Place error: \(error.localizedDescription)")
return
}
if let place = place {
let coordinates = CLLocationCoordinate2DMake(place.coordinate.latitude, place.coordinate.longitude)
let marker = GMSMarker(position: coordinates)
marker.title = place.name
marker.map = self.googleMapView
self.googleMapView.animate(toLocation: coordinates)
let geoCode = "\(place.coordinate.latitude),\(place.coordinate.longitude)"
self.showGeoSelector(title: "Selected Coordinates", message: "Latitude: " + String(place.coordinate.latitude) + " Longitude: " + String(place.coordinate.longitude), geoCode: geoCode, geoLat: String(place.coordinate.latitude), geoLong: String(place.coordinate.longitude))
}
})
}
答案 0 :(得分:0)
试试这段代码:
let geoCode = "\(String(format: "%.18f", place.coordinate.latitude)),\(String(format: "%.18f", place.coordinate.longitude))"
希望它的帮助:)