[英]Swift: How can I store coordinates using CLLocationCoordinate2D as a string or an int?
So far, this is the code I have. 到目前为止,这是我的代码。 I'm trying to store the values of locValue.latitude and locValue.longitude as either a string or an integer. 我正在尝试将locValue.latitude和locValue.longitude的值存储为字符串或整数。 I've tried defining the return type in the method ( -> String, etc.) but I get an error saying the didChangeAuthorizationStatus method conflicts with optional requirement method locationManager in protocol CLLocationManagerDelegate. 我已经尝试在方法中定义返回类型( - > String等),但是我得到一个错误,说明didChangeAuthorizationStatus方法与协议CLLocationManagerDelegate中的可选需求方法locationManager冲突。
func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus) {
if status == .AuthorizedAlways {
let locValue:CLLocationCoordinate2D = manager.location!.coordinate
self.dispLocation.text = "locations = \(locValue.latitude) \(locValue.longitude)"
}
}
Just declare two strings 只需声明两个字符串
var lat = ""
var long = ""
And the from your location parse lat
and long
并且从您的位置解析lat
和long
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let location:CLLocationCoordinate2D = manager.location!.coordinate
lat = String(location.latitude)
long = String(location.longitude)
}
you can also try this - 你也可以尝试这个 -
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation])
{
var locValue:CLLocationCoordinate2D = CLLocationCoordinate2DMake(0, 0);
if manager.location?.coordinate != nil {
locValue = (manager.location?.coordinate)!
}
let locations = "locations = \(locValue.latitude) \(locValue.longitude)"
print(locations)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.