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
- Testing apps with the location sensor simulator
- Using the GeoCoordinateWatcher class with the location sensor simulator
- Related Topics
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
In Visual Studio, run the app you want to test in the emulator.
At the bottom of the emulator toolbar, click the chevron button to open the Additional Tools window.
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
In Visual Studio, run the app you want to test in the emulator.
Open the Additional Tools window and click the Location tab.
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.
In the Search box, type the location you want to display in the map.
Click the Search button or press Enter.
The following image shows the location sensor simulator with a location specified and the Live button on.
Use the zoom controls to zoom in or out from the mapped location.
Reposition the map by dragging the map with the mouse.
Toggle the push pin button on.
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.
Stop your app when you have completed testing.
To test an app with recorded location data
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.
Open the Additional Tools window.
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.
Use the Search box to find a location you want to display in the map.
Toggle the push pin button on.
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.
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.
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.
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.
Run the portion of your app that uses the location service.
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.
Stop your app when you have completed testing.
To test an app with previously saved location data
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.
Open the Additional Tools window and click the Location tab.
In the Recorded Data pane at the lower right of the simulator, click Load.
An Open File dialog box appears.
Select the location file you want to use and click Open.
Run your app in the emulator or start the portion of your app that uses the location service.
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.
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.