One of the challenges that iPhone App developers are often faced with is how to properly test location based Apps. The iPhone simulator only provides you with the location of Apple’s headquarters in Cupertino, or alternatively the location of your own development computer. If your App’s content is based on the current location of the user, then it’s very difficult to get anywhere close to some real-world tests without having to travel around with your iPhone. Unless the content is only based in your own neighborhood it will quickly become both very time consuming and costly.
I was recently faced with the same dilemma during development of a new (still undisclosed) App until I discovered this little gem: FTLocationSimulator from FutureTap. It’s a small class that replaces some of the functionality of CLLocationManager. Instead of feeding your code the actually location of the user, it instead grabs fake locations from a KML file generated using Google Earth.
In order to use the Core Location simulator in your own projects you first need to head over to GitHub and grab a copy of the code. Once downloaded, you add the files to your project in Xcode and insert the following snippet instead of your normal initialization of CLLocationManager:
#ifdef FAKE_CORE_LOCATION [FTLocationSimulator sharedInstance].mapView = self.map; [FTLocationSimulator sharedInstance].delegate = self; [[FTLocationSimulator sharedInstance] startUpdatingLocation]; #else self.locationManager = [[[CLLocationManager alloc] init] autorelease]; self.locationManager.delegate = self; [self.locationManager startUpdatingLocation]; #endif
You need to set up a few other settings in your project, but these are all described in details in the readme file that’s part of the download so I’ll skip them here.
Once everything is set up you need to fire up Google Earth and define the path you want to simulate in your App. Save the new path as a KML file in a convenient location on your computer.
In Xcode you then double-click on your executable file and select the “Arguments” tab in the Info window. Click on the “+” button under the section called “Arguments to be passed on launch”. This will allow you to specify which KML file to use for your test by specifying -FakeLocationsRoute <KML_FILE_PATH>:
It is possible to specify more than one test file as shown above so you can quickly switch between different test routes. However only one file at a time will be used by the Core Location simulator.
It is also possible to override the default location update by specifying the launch argument -FakeLocationsUpdateInterval <INTERVAL_IN_SECONDS>.
Hopefully, when you now launch your App in the simulator you should now see your location being updated along the route you defined in Google Earth.