UPDATE: As of iOS 5 and Xcode 4.1 is is now possible to test location in the simulator and even define routes. See http://developer.apple.com for more details.
Legacy Question
Is there anyway to test CoreLocation on the iPhone Simulator?
All I require is to be able to set the location myself and have CoreLocation return it.
Here is my simple hack that forces the CLLocationMager to return the geocoords of Powell's Tech Bookstore only on the simulator:
If you're interested in updating the blue userLocation dot in a MKMapView with the simulated location updates, check out my FTLocationSimulator at http://github.com/futuretap/FTLocationSimulator
It reads a KML file generated by Google Earth to provide continuous location updates.
Use a filtering function to swap in a test instance when running on the simulator. Wherever you previously received the location (delegate call, etc), pass it through this:
Memory management issues aside...
Trigger the Core Location callbacks from a test class, if you need to set a location other than the one the simulator gives you.
the locationManager:didUpdateToLocation and locationManager:didFailedWithError overloaded callbacks are never called in the iphone simulator, that's kinda strange, all i get is 0.0000 for lat., and 0.0000 for lon. as the position. In the situation you develop something, that's kinda hard to implement all the possible situations that can occur during the location handling, using only simulator environment.
Thanks for the great feedback, it has prompted me to find a robust solution.
All the code can be found here:
http://code.google.com/p/dlocation/
It is very messy but as I use it it will be become much better.
The solution was to subclass
CLLocationManager
and define a new delegate@protocol
, calledDLocationManagerDelegate
.It is designed to be a simple drop-in replacement for
CLLocationManagerDelegate
that compiles down to a very thin layer when deployed on an actual device.When running on the device it will return data as normal using
CoreLocation
, but in the simulator it will read latitude and longitude from a text file (defined in the DLocationManager.h file).I hope this helps, the implementation is on the simple side and you have to
startUpdatingLocation
andstopUpdatingLocation
to update the display.Comments and feedback will be gratefully received.