"Desktop Map App Development" SeriesNo.6.
This time,No.5 installment adds a feature to display the device's current location on the map app created in. Sample code for the features introduced in this article is available on Esri Japan GitHub .
Displaying Current Location
ArcGIS Maps SDK for .NET (hereafter, SDK) allows you to easily display the device's current location on the map. Features are provided such as displaying a symbol at the current location and automatically navigating so that the current location stays centered on the map as it changes. The current location can use information from the device's built-in location provider, as well as externally connected GNSS devices or simulated locations (text information). This time, we will implement a feature to display the current location provided by the built-in location provider of a Windows device on the map.
1. After InitializeComponent() in MainWindow.xaml.cs, set up enabling current location display for MapView's LocationDisplay.
MainWindow.xaml.cs
public MainWindow()
{
InitializeComponent();
// Display current location on the map
MainMapView.LocationDisplay.IsEnabled = true;
MainMapView.LocationDisplay.AutoPanMode = LocationDisplayAutoPanMode.Recenter;
}
Tips: LocationDisplay's AutoPanMode has four modes available.
- Recenter: When the current location moves outside the map bounds, the map automatically moves to center the current location.
- Navigation: The current location symbol is fixed at one point on the screen, and the map automatically moves and rotates based on updates to the current location and direction of travel./
- CompassNavigation: The current location symbol is fixed at one point on the screen, and the map automatically moves and rotates according to the user's orientation (based on magnetic north)./
- Off: Only updates the position of the current location symbol on the map. The map does not move even if the current location changes.
Enable Location Services on Windows
If Location Services are disabled on your Windows
'Settings' → 'Privacy & Security' → 'App permissions' category → 'Location' → 'Location services' in that order, turn on the following items:
- 'Location services' Allow apps to access your location Allow desktop apps to access your location.
2. Try running the app. You should see a blue circle indicating your current location provided by your device's Location Services.
In No. 6 "Displaying Current Location," we introduced how to show your device's current location on a map. Next time, in No. 7, we will introduce how to implement an address search feature.
Related Links