Ich versuche, Breiten- und Längenwerte zu übernehmenvon cllocation. Es kommen volle Standortdaten. Da brauche ich nur Breiten- und Längenangaben, um mein Backend zu senden. Ich muss mehrere Breiten- und Längengrade an den Server senden.
Selbst ich habe es mit CLLocationCoordinate2D versucht, aber es ist CLLocationCoordinate in den Daten, während es an den Server gesendet wird.
Ich möchte in einem Feld sowohl Breiten- als auch Längengrade aufnehmen, nicht zwei Arrays
Kann mir jemand vorschlagen, wie man nur Längen- und Breitengrade nimmt schnell an Array anhängen?
Hier ist mein 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]
Antworten:
2 für die Antwort № 1Du kannst es versuchen
let loc = myLocations.last
let lat = currentLocation.coordinate.latitude
let lon = currentLocation.coordinate.longitude
dann erkläre arr so
var myLocations: [String] = []
let last = locations[0] as CLLocation
myLocations.append("(last.coordinate.latitude),(last.coordinate.longitude)")
1 für die Antwort № 2
var location = CLLocation()
location = myLocations.last! as CLLocation
let lat = location.coordinate.latitude
let longit = location.coordinate.longitude