Testing Location Based iPhone Apps
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.
[...] This post was mentioned on Twitter by Claus Broch, Infinite Loop. Infinite Loop said: New Blog post: Testing Location Based iPhone Apps http://t.co/8FkCpg8 [...]
is there a more easier way to change the location? i mean like an app
I’m not sure I understand what you mean by changing the location by an App. You could always implement some way of manually entering a location in a test version of your App, but I’m not sure if that’s actually easier.
I am currently developing a location based iPhone application. Is there any way to test the app other than taking the iPhone to different places?
Well, this is what this article is all about, so that would be a yes.
The user location can’t be updated for a MKMapView. So for navigation purposes, the FTLocationSimulator can’t simulate well.
NOTE: They’ve renamed iPhone Simulator to iOS Simulator so this tmneiral command doesn’t work anymore. You can still go into the folder manually (the path is provided in that tmneiral command) and just right click and select Make Alias and put the alias/shortcut wherever you want (like in your Applications folder).
Any idea if we can do something similar on the BlackBerry?
Sorry, don’t have a clue about how to code and test for BlackBerry
do you know, does this tool work well in iOS 6 and Xcode 4.5
The iPhone simulator have had location simulation built in for some time, so the method described in this article is more or less obsolete. It is possible you might get it to work, but I have not verified this myself.