How do simulate custom moving location

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?

Answered by DTS Engineer in 810171022

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

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

Is is possible to simulate speed and altitude as well?

For speed, you can add more or less points that function to serve how far a jump each clock tick makes. So if you want to simulate something going fast, you'd want contiguous points that are far apart, and for something going slow, you may want to add more points that have a smaller differential between them. As to altitude, I don't believe you can simulate that through this technique.

— Ed Ford,  DTS Engineer

Thanks for the reply. The solution you have provided above would mean that my application would need to calculate the speed manually using distance and time. But when running on a real device we can get the GPS speed without having to do any calculations. My application relies on and uses the GPS speed, which is easy to get on a real device, I don't think it would make sense to then calculate it manually just for simulators.

How do simulate custom moving location
 
 
Q