forked from jfahrenkrug/MapKit
-
Notifications
You must be signed in to change notification settings - Fork 2
/
MKGeometry.j
109 lines (88 loc) · 3.13 KB
/
MKGeometry.j
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
function MKCoordinateSpan(/*CLLocationDegrees*/ aLatitudeDelta, /*CLLocationDegrees*/ aLongitudeDelta)
{
this.latitudeDelta = aLatitudeDelta;
this.longitudeDelta = aLongitudeDelta;
return this;
}
MKCoordinateSpan.prototype.toString = function()
{
return "{" + this.latitudeDelta + ", " + this.longitudeDelta + "}";
}
function MKCoordinateSpanMake(/*CLLocationDegrees*/ aLatitudeDelta, /*CLLocationDegrees*/ aLongitudeDelta)
{
return new MKCoordinateSpan(aLatitudeDelta, aLongitudeDelta);
}
function MKCoordinateSpanFromLatLng(/*LatLng*/ aLatLng)
{
return new MKCoordinateSpan(aLatLng.lat(), aLatLng.lng());
}
function CLLocationCoordinate2D(/*CLLocationDegrees*/ aLatitude, /*CLLocationDegrees*/ aLongitude)
{
this.latitude = aLatitude;
this.longitude = aLongitude;
return this;
}
function CPStringFromCLLocationCoordinate2D(/*CLLocationCoordinate2D*/ aCoordinate)
{
return "{" + aCoordinate.latitude + ", " + aCoordinate.longitude + "}";
}
function CLLocationCoordinate2DFromString(/*String*/ aString)
{
var comma = aString.indexOf(',');
return new CLLocationCoordinate2D(
parseFloat(aString.substr(1, comma - 1)),
parseFloat(aString.substring(comma + 1, aString.length)));
}
CLLocationCoordinate2D.prototype.toString = function()
{
return CPStringFromCLLocationCoordinate2D(this);
}
function CLLocationCoordinate2DMake(/*CLLocationDegrees*/ aLatitude, /*CLLocationDegrees*/ aLongitude)
{
return new CLLocationCoordinate2D(aLatitude, aLongitude);
}
function CLLocationCoordinate2DFromLatLng(/*LatLng*/ aLatLng)
{
return new CLLocationCoordinate2D(aLatLng.lat(), aLatLng.lng());
}
function LatLngFromCLLocationCoordinate2D(/*CLLocationCoordinate2D*/ aLocation)
{
return new google.maps.LatLng(aLocation.latitude, aLocation.longitude);
}
function MKCoordinateRegion(/*CLLocationCoordinate2D*/ aCenter, /*MKCoordinateSpan*/ aSpan)
{
this.center = aCenter;
this.span = aSpan;
return this;
}
MKCoordinateRegion.prototype.toString = function()
{
return "{" +
this.center.latitude + ", " +
this.center.longitude + ", " +
this.span.latitudeDelta + ", " +
this.span.longitudeDelta + "}";
}
function MKCoordinateRegionMake(/*CLLocationCoordinate2D*/ aCenter, /*MKCoordinateSpan*/ aSpan)
{
return new MKCoordinateRegion(aCenter, aSpan);
}
function MKCoordinateRegionFromLatLngBounds(/*LatLngBounds*/ bounds)
{
return new MKCoordinateRegion(
CLLocationCoordinate2DFromLatLng(bounds.getCenter()),
MKCoordinateSpanFromLatLng(bounds.toSpan()));
}
function LatLngBoundsFromMKCoordinateRegion(/*MKCoordinateRegion*/ aRegion)
{
var latitude = aRegion.center.latitude,
longitude = aRegion.center.longitude,
latitudeDelta = aRegion.span.latitudeDelta,
longitudeDelta = aRegion.span.longitudeDelta,
LatLng = google.maps.LatLng,
LatLngBounds = google.maps.LatLngBounds;
return new LatLngBounds(
new LatLng(latitude - latitudeDelta / 2, longitude - longitudeDelta / 2), // SW
new LatLng(latitude + latitudeDelta / 2, longitude + longitudeDelta / 2) // NE
);
}