Node is saved as draft in My Content >> Draft
-
How to set MKMapView region from CLLocation array
Follow the below code to set region from CLLocation array
Here routess is an array containing CLLocation.
-(void) setRegionForMap {
MKCoordinateRegion region;
CLLocationDegrees maxLat = -90;
CLLocationDegrees maxLon = -180;
CLLocationDegrees minLat = 90;
CLLocationDegrees minLon = 180;
for(int idx = 0; idx < routess.count; idx++)
{
CLLocation* currentLocation = [routess objectAtIndex:idx];
if(currentLocation.coordinate.latitude > maxLat)
maxLat = currentLocation.coordinate.latitude;
if(currentLocation.coordinate.latitude < minLat)
minLat = currentLocation.coordinate.latitude;
if(currentLocation.coordinate.longitude > maxLon)
maxLon = currentLocation.coordinate.longitude;
if(currentLocation.coordinate.longitude < minLon)
minLon = currentLocation.coordinate.longitude;
}
region.center.latitude = (maxLat + minLat) / 2;
region.center.longitude = (maxLon + minLon) / 2;
region.span.latitudeDelta = maxLat - minLat + 0.5;
region.span.longitudeDelta = maxLon - minLon + 0.5;
if (region.center.latitude != 0 && region.center.longitude != 0) {
[mapViewUsers setRegion:region animated:YES];
} else
// set the current location region
}
}
0 Comment(s)