The Undiscoverable Kazakhstan

Kazakhstan is one of the 10th largest countries in this world. Also, it’s not usual at all to find this place on every traveler’s list. This heavenly good destination shines bright when it comes to…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




How to simulate locations in Xcode

Generally, we can work most of the time with fake data but when release is close, we want to test it with some real data and more real locations. So, let´s see how can we achieve this.

The most straight forward way of simulating a location is entering the latitude and longitude manually.

We just launch our app and in the simulator and in the Simulator menu Debug / Location / Custom Location we enter the desired coordinates.

Also, note that the simulator offers the possibility of selecting City Run, City Bicycle Ride and Freeway Drive which will to simulate the user moving at different speeds in locations close to Apple’s Headquarters.

Options iOS simulator provides

Using Custom location is ok if we do not need to do many tests, but it may be cumbersome. Every time we change the location, we may need to copy paste the latitude and longitudes or learnt them by heart. Also, it does not simulate the user moving from one location to another “naturally”

A GPX file looks something like this:

Shows the GPX points of the file above in a map of Manhattan (NY)
GPX points in the map (New York / Manhattan)

We will not dig much into the GPX file format the only thing that we need to know is that Xcode uses these waypoint elements <wpt/> that have two attributes lat and lon which respectively correspond to the latitude and longitude of the location to simulate the GPS coordinates.

Xcode will simulate the movement of the device sequentially going from the first point to the second, from the second to the third, and so on so forth. Once it arrives to the last point of the GPX file it will go back to the first one.

XCode will move user location in sequential order

Setting up Xcode
First thing we need to do is to be sure that we have the option to simulate location enabled in Xcode. This comes by default enabled, but just in case…

2. Select Edit Scheme

3. In the Run Scheme / Options tab, enable the Allow Location Simulation checkbox.

Generate the GPX file

3. Press the Save button, to give the file a meaningful name.

4. Next, press the share button at the top (next to the cog).
This will open the standard share options of iOS. Use whichever is better for you.

Import into Xcode
Now that you have the file in your Mac:

Screenshot of XCode that displays the menu Debug/Simulate Location
Menu of XCode / Debug / Simulate Location /Add GPX File to Workspace
XCode / Debug / Simulate location after adding the GPX File

Now, if you open again Debug / Simulate Location / Add GPX File to Workspace. The GPX File will appear.

You can also select the location to simulate by clicking in the location arrow icon in the Debug area of Xcode.

There are a few limitations when simulating locations using GPX files:

Work with location enabled applications includes some additional challenges during debug time, however Xcode provides a couple of build-in tools tools that helps us: manually setting the custom location and the use of GPX files.

If you liked this article share it and give it some claps 👏🏽👏🏽👏🏽👏🏽👏🏽👏🏽👏🏽👏🏽

Add a comment

Related posts:

Bad Book Ideas BLITZ

A.M. Hounchell and Edward Van Winkle (that’s me!) are posting 72 #BadBookIdeas EACH — pun-titled story pitches, be they good or bad — from 9am EST to 9pm EST on Saturday December 7th!

better late than clever

I definitely should have typed this earlier but I haven’t necessarily felt inspired to write anything meaningful or worthwhile until last night. I went on a walk with a neighbor and she was asking…

Necrosis of Good Will

Inconspicuously removed from her nose at a time when there wasn’t an audience to witness much less touch the evidence left behind, a grave of Miriam’s dry mucous had accumulated under her driver’s…