-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathUUMapView.m
More file actions
84 lines (73 loc) · 1.94 KB
/
UUMapView.m
File metadata and controls
84 lines (73 loc) · 1.94 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//
// UUMapView.m
// Useful Utilities - MKMapView extensions
//
// Created by Jonathan on 3/4/13.
//
// License:
// You are free to use this code for whatever purposes you desire. The only requirement is that you smile everytime you use it.
//
// Contact: @cheesemaker or jon@threejacks.com
#import "UUMapView.h"
@implementation MKMapView (UUFramework)
+ (bool) uuFindBoundingBox:(NSArray*)annotations bounds:(MKCoordinateRegion*)boundingBox
{
CLLocationDegrees minLat = INT_MAX;
CLLocationDegrees maxLat = INT_MIN;
CLLocationDegrees minLng = INT_MAX;
CLLocationDegrees maxLng = INT_MIN;
bool foundMinLat = false;
bool foundMinLng = false;
bool foundMaxLat = false;
bool foundMaxLng = false;
for (NSObject<MKAnnotation>* annotation in annotations)
{
CLLocationDegrees lat = annotation.coordinate.latitude;
CLLocationDegrees lng = annotation.coordinate.longitude;
if (lat != 0.0 || lng!= 0.0)
{
if (lat < minLat)
{
minLat = lat;
foundMinLat = true;
}
if (lat > maxLat)
{
maxLat = lat;
foundMaxLat = true;
}
if (lng < minLng)
{
minLng = lng;
foundMinLng = true;
}
if (lng > maxLng)
{
maxLng = lng;
foundMaxLng = true;
}
}
}
if (foundMinLat && foundMinLng && foundMaxLat && foundMaxLng)
{
(*boundingBox).center.latitude = minLat + ((maxLat - minLat) / 2.0f);
(*boundingBox).center.longitude = minLng + ((maxLng - minLng) / 2.0f);
(*boundingBox).span.latitudeDelta = fabs(maxLat - minLat);
(*boundingBox).span.longitudeDelta = fabs(maxLng - minLng);
return true;
}
else
{
return false;
}
}
- (void) uuZoomToAnnotations:(bool)animated
{
MKCoordinateRegion region;
if ([MKMapView uuFindBoundingBox:self.annotations bounds:®ion])
{
region = [self regionThatFits:region];
[self setRegion:region animated:animated];
}
}
@end