For some background, my app is a Flutter app and I have opened it in xcode to try the following, I can build and run it on a simulator from xcode as well.
I want to be able to simulate custom moving locations for my app. I tried going to Debug -> Simulate Location like online tutorials show but it is all greyed out.
I have location simulation enabled (I have tried changing the default location too):
Within the simulator itself I only have the predefined routes or a custom static location with no option for a moving location.
How can I simulate a custom moving location?
If it isn't possible is there anyway to simulate the location for a Mac app as I can build the Flutter app for Mac as well?
To simulate your own location sequence, you need to create a GPX file using the waypoint <wpt>
tag. Here's a very small example:
<?xml version="1.0"?>
<gpx version="1.1" creator="Xcode">
<wpt lat="36.50938326" lon="-121.76772372"/>
<wpt lat="36.50923886" lon="-121.76780457"/>
<wpt lat="36.50970096" lon="-121.76883763"/>
<wpt lat="36.5098598" lon="-121.76930476"/>
<wpt lat="36.50952045" lon="-121.76943052"/>
<wpt lat="36.50849516" lon="-121.76936764"/>
<wpt lat="36.50832909" lon="-121.76941256"/>
<wpt lat="36.50635068" lon="-121.76949341"/>
<wpt lat="36.50601853" lon="-121.76943052"/>
<wpt lat="36.50581636" lon="-121.76934069"/>
<wpt lat="36.50526759" lon="-121.76943951"/>
<wpt lat="36.50498598" lon="-121.76945747"/>
<wpt lat="36.50468993" lon="-121.76914306"/>
<wpt lat="36.50233594" lon="-121.76306147"/>
<wpt lat="36.5023937" lon="-121.7630435"/>
</gpx>
If you're creating a GPS track using something like an external GPS hardware unit that allows you to trace your steps, you may find it uses the route <rte>
or track <trk>
tags, which aren't used by Xcode for location simulation.
With this file added to your Xcode project, you can then set it in the Default Location menu shown in your screenshot.
In your code, you'll see Core Location returning one coordinate from this file for each time it provides a location update in this app. So for the above example, you will receive the 15 location coordinates sequentially, once per location update, and then the system will loop back to the first location.
—Ed Ford, DTS Engineer