public
Created

Client iOS Map Center

  • Download Gist
gistfile1.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
if (supportsMaps_)
{
BOOL initialized = NO;
CLLocationDegrees minLat = -1000.0f;
CLLocationDegrees maxLat = 1000.0f;
CLLocationDegrees minLong = -1000.0f;
CLLocationDegrees maxLong = 1000.0f;
// We support maps, loop over houses to find the region to fit
for (Household *household in [self households])
{
if ([household hasCoordinate])
{
CLLocationCoordinate2D coord = [household coordinate];
if (!initialized)
{
minLat = coord.latitude;
maxLat = coord.latitude;
minLong = coord.longitude;
maxLong = coord.longitude;
initialized = YES;
}
else
{
if (coord.latitude < minLat) { minLat = coord.latitude; }
if (coord.latitude > maxLat) { maxLat = coord.latitude; }
if (coord.longitude < minLong) { minLong = coord.longitude; }
if (coord.longitude > maxLong) { maxLong = coord.longitude; }
}
}
}
MKCoordinateSpan span = MKCoordinateSpanMake( fabs(maxLat-minLat), fabs(maxLong-minLong));
CLLocationCoordinate2D center;
center.latitude = minLat + (span.latitudeDelta/2.0f);
center.longitude = minLong + (span.longitudeDelta/2.0f);
householdMapRegion_ = MKCoordinateRegionMake(center, span);
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.