Caleb Caleb - 5 months ago 19
Swift Question

Need help sending location data to a server in Xcode

I don't have a server set up yet, but my app requires the location of other people on the app to work. I need help taking each location and putting it with all the others in an array to be used, and later sent back to the phone. Thanks in advance.

func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation])
{
let location = locations.last
let center = CLLocationCoordinate2D(latitude: location!.coordinate.latitude, longitude: location!.coordinate.longitude)
let region = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: 1, longitudeDelta: 1))
self.mapView.setRegion(region, animated: true)
self.locationManager.stopUpdatingLocation()//
}

Answer

I am not sure if I understand your intent completely, but here are some ad hoc comments:

Dictionary might be more practical data storage for this purpose. Individual users can be added/removed, directly accessed when the user position changes and needs to be updated and if you want, you can access the data in the same fashion as Array.

Consider using requestLocation instead of didUpdateLocations if you need just one reading.

I think CloudKit might have all you need to implement the server part.