RMUserLocation.m
1.98 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
//
// RMUserLocation.m
// MapView
//
// Created by Justin Miller on 5/8/12.
// Copyright (c) 2012 MapBox / Development Seed. All rights reserved.
//
#import "RMUserLocation.h"
#import "RMMarker.h"
#import "RMMapView.h"
@implementation RMUserLocation
@synthesize updating;
@synthesize location;
@synthesize heading;
- (id)initWithMapView:(RMMapView *)aMapView coordinate:(CLLocationCoordinate2D)aCoordinate andTitle:(NSString *)aTitle
{
if ( ! (self = [super initWithMapView:aMapView coordinate:aCoordinate andTitle:aTitle]))
return nil;
NSAssert([[NSBundle mainBundle] pathForResource:@"TrackingDot" ofType:@"png"], @"Unable to find necessary graphical assets (copy from framework 'Resources' folder)");
layer = [[RMMarker alloc] initWithUIImage:[UIImage imageNamed:@"TrackingDot.png"]];
layer.zPosition = -MAXFLOAT + 2;
annotationType = [kRMUserLocationAnnotationTypeName retain];
clusteringEnabled = NO;
return self;
}
- (void)dealloc
{
[layer release]; layer = nil;
[annotationType release]; annotationType = nil;
[location release]; location = nil;
[heading release]; heading = nil;
[super dealloc];
}
- (BOOL)isUpdating
{
return (self.mapView.userTrackingMode != RMUserTrackingModeNone);
}
- (void)setLocation:(CLLocation *)newLocation
{
if ([newLocation distanceFromLocation:location] && newLocation.coordinate.latitude != 0 && newLocation.coordinate.longitude != 0)
{
[self willChangeValueForKey:@"location"];
[location release];
location = [newLocation retain];
self.coordinate = location.coordinate;
[self didChangeValueForKey:@"location"];
}
}
- (void)setHeading:(CLHeading *)newHeading
{
if (newHeading.trueHeading != heading.trueHeading)
{
[self willChangeValueForKey:@"heading"];
[heading release];
heading = [newHeading retain];
[self didChangeValueForKey:@"heading"];
}
}
- (BOOL)isUserLocationAnnotation
{
return YES;
}
@end