-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMKLocation.j
55 lines (44 loc) · 1.28 KB
/
MKLocation.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
MKLocationStringRegEx = /\s*<(\-?\d*\.?\d*),\s*(\-?\d*\.?\d*)>\s*$/;
@implementation MKLocation : CPObject
{
float _latitude @accessors(property=latitude);
float _longitude @accessors(property=longitude);
}
+ (MKLocation)location
{
return [[MKLocation alloc] init];
}
+ (MKLocation)locationWithLatitude:(float)aLat andLongitude:(float)aLng {
return [[MKLocation alloc] initWithLatitude:aLat andLongitude:aLng];
}
//create a location from a String like this:
//san jose <37.3393857, -121.8949555>
+ (MKLocation)locationFromString:(CPString)aString
{
var res = MKLocationStringRegEx.exec(aString);
if (res && res.length === 3)
{
return [MKLocation locationWithLatitude:res[1] andLongitude:res[2]];
}
return nil;
}
- (id)initWithLatLng:(LatLng)aLatLng {
return [self initWithLatitude:aLatLng.lat() andLongitude:aLatLng.lng()];
}
- (id)initWithLatitude:(float)aLat andLongitude:(float)aLng
{
if (self = [super init]) {
_latitude = aLat;
_longitude = aLng;
}
return self;
}
- (LatLng)googleLatLng {
var gm = [MKMapView gmNamespace];
return new gm.LatLng(_latitude, _longitude);
}
- (void)encodeWithCoder:(CPCoder)coder
{
[coder encodeObject:[_latitude, _longitude] forKey:@"location"];
}
@end