Partager via


How to test apps that use location data for Windows Phone 8

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

The Windows Phone SDK includes a location sensor simulator. This topic describes how to test apps that use location data.

You can find a code sample that uses the location service at Samples gallery on Windows Phone Dev Center.

This topic contains the following sections.

Viewing the location sensor simulator

You can view the location sensor simulator from Windows Phone Emulator. The location sensor simulator toolbar contains controls to find a location, add points to the mapped location, and record and play back your location data.

To view the location sensor simulator

  1. In Visual Studio, run the app you want to test in the emulator.

  2. At the bottom of the emulator toolbar, click the chevron button to open the Additional Tools window.

  3. Click the Location tab to view the location sensor simulator.

    The following image shows the location sensor simulator toolbar.

1

Search

2

Zoom

3

Toggle live interactions with map on or off

4

Toggle push pin mode on or off

5

Clear all points

6

Save map points

7

Interval in seconds

8

Play all points

Testing apps with the location sensor simulator

You can test the location sensor with the following types of location data.

  • Live data that you enter in the simulator as the app runs.

  • Recorded data that you entered in the simulator before running your app.

  • Recorded data that you saved in a file from a previous session.

The location sensor simulator cannot load more than 99 locations.

To test an app with live input of location data

  1. In Visual Studio, run the app you want to test in the emulator.

  2. Open the Additional Tools window and click the Location tab.

  3. Make sure the live input mode is on by toggling the Live button.

    If the Live button is grayed out, live input mode is off.

  4. In the Search box, type the location you want to display in the map.

  5. Click the Search button or press Enter.

    The following image shows the location sensor simulator with a location specified and the Live button on.

  6. Use the zoom controls to zoom in or out from the mapped location.

  7. Reposition the map by dragging the map with the mouse.

  8. Toggle the push pin button on.

  9. Click the map to add points to the map.

    Each time you add a point to the map, the PositionChanged event will be raised in your app.

  10. Stop your app when you have completed testing.

To test an app with recorded location data

  1. In Visual Studio, open the project you want to test and start Windows Phone Emulator. The portion of your app that uses the Location service must not be running.

  2. Open the Additional Tools window.

  3. Make sure the live input mode is off by toggling the Live button.

    If the Live button is grayed out, live input mode is off.

  4. Use the Search box to find a location you want to display in the map.

  5. Toggle the push pin button on.

  6. Click the map to add points to the map.

    Each time you add a point, an entry is added to the list at the lower left of the simulator. The following image shows the location sensor simulator with a location specified, live mode turned off, and several points added to the map.

  7. To delete a point added in error, locate the point in the list at the lower left of the simulator and then click the Delete point button to the right of the point.

    You can delete all of the points by clicking the Clear all points button on the toolbar.

  8. To enter the time interval that should elapse between points on the map, specify the number of seconds in the Fire every box.

    This number indicates the time interval (in seconds) between each occurrence of the PositionChanged event in your app.

  9. Optionally, you can save your data to a file by clicking the Save map points button. If you save the data, you can use it in subsequent test passes.

    When the Save As dialog box appears, specify a file name and click Save. The file is saved as an XML file in the \Documents\WindowsPhoneEmulator\Location folder.

  10. Run the portion of your app that uses the location service.

  11. In the Location simulator, on the right side of the toolbar, click the Play all points button to start playback of the recorded location data.

    You can play back the location data as many times as necessary to test your app.

  12. Stop your app when you have completed testing.

To test an app with previously saved location data

  1. In Visual Studio, open the project you want to test. Start Windows Phone Emulator. The portion of your app that uses the location service must not be running.

  2. Open the Additional Tools window and click the Location tab.

  3. In the Recorded Data pane at the lower right of the simulator, click Load.

    An Open File dialog box appears.

  4. Select the location file you want to use and click Open.

  5. Run your app in the emulator or start the portion of your app that uses the location service.

  6. On the right side of the toolbar, click the Play all points button to start playback of the recorded location data.

    You can play back the location data as many times as necessary to test your app.

    The following image shows previously recorded data displayed in the simulator.

  7. Stop your app when you have completed testing.

Using the GeoCoordinateWatcher class with the location sensor simulator

If your app uses the GeoCoordinateWatcher class, you have to specify a value of GeoPositionAccuracy..::.High in the constructor or in the DesiredAccuracy property of the class before you can test your app with the location sensor simulator. If you leave the accuracy at its default value of GeoPositionAccuracy..::.Default, the PositionChanged event doesn’t recognize position changes that occur in the location sensor simulator.

However, positions obtained with a setting of GeoPositionAccuracy..::.Default are satisfactory for many applications. Obtaining a high-accuracy position is slower and consumes more power. If your app doesn’t require a high-accuracy position, you can reset the accuracy value from High to Default after you finish testing your app in the emulator.

See Also

Other Resources

How to use the .NET Location API for Windows Phone 8

How to deploy and run an app for Windows Phone 8