我试图将纬度和经度传递给url参数,但返回Nil,但是当我在委托中打印时,它返回经度和纬度,而且我似乎找不到问题,我尝试了许多不同的方法似乎没有任何作用
这是我存储纬度和经度的变量var lat: Double! var long: Double!
这是我的代表
func locationManager(_ manager:CLLocationManager, didUpdateLocations locations: [CLLocation]){
currentLocation = manager.location!.coordinate
let locValue:CLLocationCoordinate2D = currentLocation!
self.long = locValue.longitude
self.lat = locValue.latitude
print(lat)
print(long)
}
然后将它们传递给我在URL参数中使用的变量,但它们返回nil,我不明白为什么
let userLat = String(describing: lat)
let userLong = String(describing: long)
谢谢
最佳答案
尝试类似的方法:
迅捷3
func locationManager(_ manager:CLLocationManager, didUpdateLocations locations: [CLLocation]){
if let last = locations.last {
sendLocation(last.coordinate)
}
}
func sendLocation(_ coordinate: CLLocationCoordinate2D) {
let userLat = NSString(format: "%f", coordinate.latitude) as String
let userLong = NSString(format: "%f", coordinate.longitude) as String
// Run API Call....
}
关于ios - 从CLLocationManager传递经度和纬度到URL?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44401447/