Reputation: 1153
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()//
}
Upvotes: 1
Views: 128
Reputation: 11555
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.
In order to find the region of the map that encompasses all locations, you need to take all coordinates and find top left and bottom right coordinate and use that in the MKCoordinateRegion
Upvotes: 1