Testing CoreLocation on iPhone Simulator

UPDATE:. Starting with iOS 5 and Xcode 4.1, you can now check the location in the simulator and even determine the routes. See http://developer.apple.com for more details.

Outdated question

Do I need to test CoreLocation on iPhone Simulator?

All I need to do is set the location on my own and return CoreLocation.

+29
ios iphone cocoa-touch core-location
Apr 29 '09 at 12:37
source share
8 answers

Thanks for the excellent feedback, it prompted me to find a reliable solution.

All code can be found here:

http://code.google.com/p/dlocation/

This is very dirty, but as you use it, it will become much better.

The solution was to subclass CLLocationManager and define a new @protocol delegate called DLocationManagerDelegate .

It is designed to be a simple replacement for CLLocationManagerDelegate , which CLLocationManagerDelegate at a very subtle level when deployed to a real device.

When launched on the device, it will return data as usual using CoreLocation , but in the simulator it will read the latitude and longitude from a text file (defined in the DLocationManager.h file).

Hope this helps, the implementation is done on the simple side, and you need startUpdatingLocation and stopUpdatingLocation update the display.

Comments and feedback will be gratefully received.

+18
May 01 '09 at 17:39
source share

Here is my simple hack that forces the CLLocationMager to return Powell Tech Bookstore geocoders on a simulator only:

 #ifdef TARGET_IPHONE_SIMULATOR @interface CLLocationManager (Simulator) @end @implementation CLLocationManager (Simulator) -(void)startUpdatingLocation { CLLocation *powellsTech = [[[CLLocation alloc] initWithLatitude:45.523450 longitude:-122.678897] autorelease]; [self.delegate locationManager:self didUpdateToLocation:powellsTech fromLocation:powellsTech]; } @end #endif // TARGET_IPHONE_SIMULATOR 
+20
Jul 21 '10 at 22:24
source share

Use the filter function to replace in the test instance when running on the simulator. Wherever you have previously received a location (calling a delegate, etc.), go through this:

 + (CLLocation *) wakkawakka: (CLLocation*) loc { #ifdef TARGET_IPHONE_SIMULATOR /* replace with a test instance */ return [[CLLocation alloc] initWithLatitude:10.0 longitude:20.0]; #else return loc; #endif } 

Problems with memory management aside ...

+13
Apr 29 '09 at 17:41
source share

I think that a different (better IMHO) approach is used here than a subclassification of CLLocationManager, for example in

http://code.google.com/p/dlocation/

In ObjectiveC, it seems possible to replace an existing method from a class without overriding it. This is often called the "swizzling method": you define your own category for an existing class, implement the existing method in it.

From the clientโ€™s point of view, everything is transparent: he has a feeling that he is dealing with a real CLLocationManager , but in fact you โ€œtook control from himโ€ . So he does not need to deal with any special subclass or any special delegation protocol: he continues to use the same class / protocol as the one from CoreLocation.

Here is an example to take control of the delegate that the client will enter:

 @implementation CLLocationManager () 

- (void) setDelegate: (id) delegate { // setDelegate... } - (id) { // .... } - (void) startUpdatingLocation { } - (void) stopUpdatingLocation { } //.... // , CLLocationManager @

Then, in this implementation, you can deal with a predefined set of coordinates (coming from a file of any type) that will be โ€œpushedโ€ to the delegate using the standard CLLocationManagerDelegate protocol.

+9
Jan 13 '10 at 21:12
source share

Run Core Location callbacks from the test class if you need to set a different place than what the simulator gives you.

+2
Apr 29 '09 at 15:04
source share

locationManager: didUpdateToLocation and locationManager: didFailedWithError overloaded callbacks are never called in the iphone simulator, this is strange, all I get is 0.0000 for lat. and 0.0000 for lon. as a position. In a situation, you are developing something that it is difficult to realize all the possible situations that may arise during the processing of a location using only the simulator environment.

+2
Oct 11 2018-10-10
source share

If you are interested in updating the blue userLocation point in MKMapView with simulated location updates, check out my FTLocationSimulator at http://github.com/futuretap/FTLocationSimulator

It reads a KML file created by Google Earth to provide continuous location updates.

+2
Oct 27 '10 at 8:36
source share

Testing CoreLocation on iPhone Simulator

1) To check the location in the simulator, it is best to use GPX files, just go to Files โ†’ New โ†’ Resource โ†’ GPX File.

2) After adding the GPX file update, location coordinates are optional.

3) after adding the GPX file to the project, select Scheme โ†’ Change Scheme โ†’ Run โ†’ Allow Location Determination . Select a location simulation and select the GPX file name you just created.

Thus, the simulator will always select the desired coordinates that we added to our GPX file.

Create GPX File

+1
Jun 30 '17 at 10:36
source share



All Articles