I am trying to take latitude and longitude values from cllocation. Its coming full location data. Since I need only latitude and longitude data to send my back end. I have to send multiple latitude and longitude data to server.
Even I tried with CLLocationCoordinate2D, but, its taking CLLocationCoordinate inside the data while sending to server.
I want to take in single array both latitude and longitude, not in two arrays.
Can anyone suggest me, how to take only latitude and longitude values to append to array in swift?
Here is my code
var myLocations: [CLLocation] = []
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
myLocations.append(locations[0] as CLLocation)
}
output is
<+10.92088132,+77.56955708> +/- 1414.00m (speed -1.00 mps / course -1.00) @ 22/03/18, 1:17:30 PM India Standard Time
[<+10.92088132,+77.56955708> +/- 1414.00m (speed -1.00 mps / course -1.00) @ 22/03/18, 1:17:30 PM India Standard Time]
You can try
let loc = myLocations.last
let lat = currentLocation.coordinate.latitude
let lon = currentLocation.coordinate.longitude
then declare arr like this
var myLocations: [String] = []
let last = locations[0] as CLLocation
myLocations.append("\(last.coordinate.latitude),\(last.coordinate.longitude)")