There are times that you will want to simulate a position for testing GPS in an application you are working on, apart from getting on a plane or grabbing the car keys there is another way to do it, and it’s quicker!
In Xcode you can either select a location or, as I will demonstrate, you can add a position using a gpx file.
To do this, you will need an active session, so go ahead and run your application in Xcode and open up the debugging window ( Shift + CMD + Y ) or View > Debug Area > Show Debug Area.
Do you notice the Arrow on the toolbar for the Window that looks just like the GPS one on an iPhone? Click on it and a menu will appear.
Notice that not only do we have a list of pre-defined locations we can select from, but we can also add our own. So how do we do that?
To The Web Batman!
OK let’s leave Xcode for a second and pull up the following Web page, http://www.gpx-poi.com. This wonderful Web application is going to generate the file with all the right data that we need.
As you can see, there is a lot of different ways to create a file for the location you want, but we are going to keep it simple. We are going to create a location for the Big Ben clock in London. So I happen to know the address is Parliament Square, Westminster, St Margaret Street, London SW1A 0AA. Enter the location details and at the bottom of the page there is a field for file name (.gpx). I’ll enter Big Ben – London. Now I just have to click Download and the file will download to my machine.
Now back in Xcode, open up the menu again from the debugger bar and choose Add GPX File to Project… at the bottom of the menu, and load the file just downloaded. You may have to rename the file first, when I downloaded the file it had a .txt extension, just remove that and ensure it has .gpx extension. Just click finish when the dialog box comes up asking if you want to import the file into the project.
Now when you open up the menu again you should see the newly imported location added to the list.
You will most likely need the Latitude and Longitude coordinates for the location you want to use for it to work properly. But that is all you need to do for adding custom locations in Xcode projects.