Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 206 lines (181 sloc) 6.463 kB
a6b9edf @futuretap Added CoreLocation Simulator
authored
1 //
2 // FTLocationSimulator.m
3 //
4 // Created by Ortwin Gentz on 23.09.2010.
877ea49 @futuretap Added license disclaimer
authored
5 // Copyright 2010 FutureTap http://www.futuretap.com
6 // All rights reserved.
a6b9edf @futuretap Added CoreLocation Simulator
authored
7 //
877ea49 @futuretap Added license disclaimer
authored
8 // Permission is given to use this source code file without charge in any
9 // project, commercial or otherwise, entirely at your risk, with the condition
10 // that any redistribution (in part or whole) of source code must retain
11 // this copyright and permission notice. Attribution in compiled projects is
12 // appreciated but not required.
a6b9edf @futuretap Added CoreLocation Simulator
authored
13
14 #import "FTLocationSimulator.h"
6196dc9 @futuretap Prefixed SynthesizeSingleton for compatibility with other projects us…
authored
15 #import "FTSynthesizeSingleton.h"
a6b9edf @futuretap Added CoreLocation Simulator
authored
16 #import "RegexKitLite.h"
17
18 @implementation FTLocationSimulator
19
20 SYNTHESIZE_SINGLETON_FOR_CLASS(FTLocationSimulator)
21
22 @synthesize location;
f050e56 @futuretap FTLocationSimulator now works as a drop-in replacement for CLLocation…
authored
23 @synthesize oldLocation;
a6b9edf @futuretap Added CoreLocation Simulator
authored
24 @synthesize delegate;
f050e56 @futuretap FTLocationSimulator now works as a drop-in replacement for CLLocation…
authored
25 @synthesize distanceFilter;
26 @synthesize purpose;
a6b9edf @futuretap Added CoreLocation Simulator
authored
27 @synthesize mapView;
28
29 - (void)dealloc
30 {
31 [mapView release];
32 mapView = nil;
33
34 [location release];
35 location = nil;
36
f050e56 @futuretap FTLocationSimulator now works as a drop-in replacement for CLLocation…
authored
37 [purpose release];
38 purpose = nil;
39
a6b9edf @futuretap Added CoreLocation Simulator
authored
40 [super dealloc];
41 }
42
43 - (void)fakeNewLocation {
44 // read and parse the KML file
45 if (!fakeLocations) {
fab4542 @InfiniteLoopDK Added option for overriding default locations route and update interv…
InfiniteLoopDK authored
46 NSString *fakeLocationsPath = [[NSUserDefaults standardUserDefaults] stringForKey:@"FakeLocationsRoute"];
47 if(!fakeLocationsPath)
48 fakeLocationsPath = [[NSBundle mainBundle] pathForResource:@"fakeLocations" ofType:@"kml"];
49
50 NSString *fakeLocationsFile = [[NSString alloc] initWithContentsOfFile:fakeLocationsPath];
a6b9edf @futuretap Added CoreLocation Simulator
authored
51 NSString *coordinatesString = [fakeLocationsFile stringByMatching:@"<coordinates>[^-0-9]*(.+?)[^-0-9]*</coordinates>"
52 options:RKLMultiline|RKLDotAll
53 inRange:NSMakeRange(0, fakeLocationsFile.length)
54 capture:1
55 error:NULL];
eea47f0 @below Now handes more kml files
below authored
56 NSScanner *scanner = [NSScanner scannerWithString:coordinatesString];
57 while ([scanner isAtEnd] == NO) {
58 NSString *coordinate = nil;
59 [scanner scanUpToCharactersFromSet:[NSCharacterSet whitespaceAndNewlineCharacterSet] intoString:&coordinate];
60 if (fakeLocations == nil)
61 fakeLocations = [[NSMutableArray alloc] init];
62 [(NSMutableArray*)fakeLocations addObject:coordinate];
63 }
a6b9edf @futuretap Added CoreLocation Simulator
authored
64 [fakeLocationsFile release];
fab4542 @InfiniteLoopDK Added option for overriding default locations route and update interv…
InfiniteLoopDK authored
65
66 if([[NSUserDefaults standardUserDefaults] objectForKey:@"FakeLocationsUpdateInterval"])
67 updateInterval = [[NSUserDefaults standardUserDefaults] doubleForKey:@"FakeLocationsUpdateInterval"];
68 else
69 updateInterval = FAKE_CORE_LOCATION_UPDATE_INTERVAL;
a6b9edf @futuretap Added CoreLocation Simulator
authored
70 }
71
72 // select a new fake location
73 NSArray *latLong = [[fakeLocations objectAtIndex:index] componentsSeparatedByString:@","];
74 CLLocationDegrees lat = [[latLong objectAtIndex:1] doubleValue];
75 CLLocationDegrees lon = [[latLong objectAtIndex:0] doubleValue];
76 self.location = [[[CLLocation alloc] initWithCoordinate:CLLocationCoordinate2DMake(lat, lon)
77 altitude:0
78 horizontalAccuracy:0
79 verticalAccuracy:0
80 timestamp:[NSDate date]] autorelease];
81
82 // update the userlocation view
83 if (self.mapView) {
84 MKAnnotationView *userLocationView = [self.mapView viewForAnnotation:self.mapView.userLocation];
85 [userLocationView.superview sendSubviewToBack:userLocationView];
e0cf05d @futuretap changed the directory structure
authored
86
87 CGRect frame = userLocationView.frame;
a6b9edf @futuretap Added CoreLocation Simulator
authored
88 frame.origin = [self.mapView convertCoordinate:self.location.coordinate toPointToView:userLocationView.superview];
89 frame.origin.x -= 10;
90 frame.origin.y -= 10;
91 [UIView beginAnimations:@"fakeUserLocation" context:nil];
fab4542 @InfiniteLoopDK Added option for overriding default locations route and update interv…
InfiniteLoopDK authored
92 [UIView setAnimationDuration:updateInterval];
f050e56 @futuretap FTLocationSimulator now works as a drop-in replacement for CLLocation…
authored
93 [UIView setAnimationCurve:UIViewAnimationCurveLinear];
a6b9edf @futuretap Added CoreLocation Simulator
authored
94 userLocationView.frame = frame;
95 [UIView commitAnimations];
e0cf05d @futuretap changed the directory structure
authored
96
9c1261a @futuretap Fixed error in LLVM-compiler, cannot set readonly-property via dot-sy…
authored
97 [self.mapView.userLocation setCoordinate:self.location.coordinate];
a6b9edf @futuretap Added CoreLocation Simulator
authored
98 }
99
100 // inform the locationManager delegate
f050e56 @futuretap FTLocationSimulator now works as a drop-in replacement for CLLocation…
authored
101 if((!self.oldLocation || [self.location distanceFromLocation:oldLocation] > distanceFilter) &&
102 [self.delegate respondsToSelector:@selector(locationManager:didUpdateToLocation:fromLocation:)]) {
a6b9edf @futuretap Added CoreLocation Simulator
authored
103 [self.delegate locationManager:nil
104 didUpdateToLocation:self.location
105 fromLocation:oldLocation];
f050e56 @futuretap FTLocationSimulator now works as a drop-in replacement for CLLocation…
authored
106 self.oldLocation = self.location;
a6b9edf @futuretap Added CoreLocation Simulator
authored
107 }
108
109 // iterate to the next fake location
110 if (updatingLocation) {
111 index++;
112 if (index == fakeLocations.count) {
113 index = 0;
114 }
115
fab4542 @InfiniteLoopDK Added option for overriding default locations route and update interv…
InfiniteLoopDK authored
116 [self performSelector:@selector(fakeNewLocation) withObject:nil afterDelay:updateInterval];
a6b9edf @futuretap Added CoreLocation Simulator
authored
117 }
118 }
119
120 - (void)startUpdatingLocation {
121 updatingLocation = YES;
122 [self fakeNewLocation];
123 }
124
125 - (void)stopUpdatingLocation {
126 updatingLocation = NO;
127 }
128
129 - (MKAnnotationView*)fakeUserLocationView {
130 if (!self.mapView) {
131 return nil;
132 }
9c1261a @futuretap Fixed error in LLVM-compiler, cannot set readonly-property via dot-sy…
authored
133
134 [self.mapView.userLocation setCoordinate:self.location.coordinate];
a6b9edf @futuretap Added CoreLocation Simulator
authored
135 MKAnnotationView *userLocationView = [[MKAnnotationView alloc] initWithAnnotation:self.mapView.userLocation reuseIdentifier:nil];
136 [userLocationView addSubview:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"TrackingDot.png"]]];
137 userLocationView.centerOffset = CGPointMake(-10, -10);
138 return userLocationView;
139 }
140
f050e56 @futuretap FTLocationSimulator now works as a drop-in replacement for CLLocation…
authored
141
142 // dummy methods to keep the CLLocationManager interface
143 + (BOOL)locationServicesEnabled {
144 return [FTLocationSimulator sharedInstance].locationServicesEnabled;
145 }
146 + (BOOL)headingAvailable {
147 return NO;
148 }
149 + (BOOL)significantLocationChangeMonitoringAvailable {
150 return NO;
151 }
152 + (BOOL)regionMonitoringAvailable {
153 return NO;
154 }
155 + (BOOL)regionMonitoringEnabled {
156 return NO;
157 }
158 + (CLAuthorizationStatus)authorizationStatus {
159 return kCLAuthorizationStatusAuthorized;
160 }
161 - (BOOL)locationServicesEnabled {
162 return updatingLocation;
163 }
164 - (CLLocationAccuracy) desiredAccuracy {
165 return kCLLocationAccuracyBest;
166 }
167 - (void)setDesiredAccuracy:(CLLocationAccuracy)desiredAccuracy {
168 }
169 - (BOOL)headingAvailable {
170 return NO;
171 }
172 - (CLLocationDegrees) headingFilter {
173 return kCLHeadingFilterNone;
174 }
175 - (void)setHeadingFilter:(CLLocationDegrees)headingFilter {
176 }
177 - (CLDeviceOrientation) headingOrientation {
178 return CLDeviceOrientationPortrait;
179 }
180 - (void)setHeadingOrientation:(CLDeviceOrientation)headingOrientation {
181 }
182 - (CLHeading*) heading {
183 return nil;
184 }
185 - (CLLocationDistance) maximumRegionMonitoringDistance {
186 return kCLErrorRegionMonitoringFailure;
187 }
188 - (NSSet*)monitoredRegions {
189 return nil;
190 }
191 - (void)startUpdatingHeading {
192 }
193 - (void)stopUpdatingHeading {
194 }
195 - (void)dismissHeadingCalibrationDisplay {
196 }
197 - (void)startMonitoringSignificantLocationChanges {
198 }
199 - (void)stopMonitoringSignificantLocationChanges {
200 }
201 - (void)startMonitoringForRegion:(CLRegion*)region desiredAccuracy:(CLLocationAccuracy)accuracy {
202 }
203 - (void)stopMonitoringForRegion:(CLRegion*)region {
204 }
a6b9edf @futuretap Added CoreLocation Simulator
authored
205 @end
Something went wrong with that request. Please try again.