This is the forth blog in a series of posts reviewing the new ArcGIS Runtime (beta) mapping SDK. The new SDK will be a great companion for any Windows developer wanting to add map functionality to their apps. In part 3, we looked at the MapView control within the SDK. One of the dependency properties that I left off in that post is the LocationDisplay property. This post will go into that property extensively. Working with location is probably my favorite part of the new ArcGIS Runtime mapping SDK because it is just so damn simple. In most mapping SDKs (eg: Nokia, Bing) you must do the work of hooking up to location changes, and updating the map. In the ArcGIS Runtime mapping SDK, it’s handled for you if you opt in for this functionality. Start off by downloading the sample application (if you have not done so already).
The LocationDisplay property of the MapView provides access to the LocationDisplay class. This class provides access to all the properties that make working with location in the SDK pure awesomesauce. Turning on location tracking, and the display of location on the map is as simple as setting IsEnabled to true! Let me say that again, setting one property to true, enabled GPS location within your app, places a symbol on the map indicating the current location, tracks location changes, and updates the symbol when location changes. Let’s take a look at the xaml needed to make this happen. Open up the xaml of any of the pages in the app. I’ll open the ArcGISTiledLayerPage.
Enable the Location capability in your app (open Package.appxmanifest, Capabilities tab) and start the application. Select the map that you edited and it will prompt you to use location,
Allow location, and you’ll see your location on the map!
Unfortunately our location not centered on the map. If you want to track location, and center the map on the user, you’ll want to change the AutoPanMode. The AutoPanMode enumeration is a little confusing because the default value of the enum is Off, despite having a member named Default. I agree that you do not want the default value to center the map, but the wording is confusing. I’d like to see those change to Default, and On rather than Off and Default.
<location:LocationDisplay IsEnabled="True" AutoPanMode="Default" />
With our enum set to Default, the map now centers on the device! The location will update when you move and the map will re-center as well!
The AutoPanMode has two other values that make working with location even more awesome! Setting AutoPanMode to Navigation will change the map Rotation so that the top of the map faces the direction the user is facing. This is great for building routing apps where you want the road or path the user is driving, walking on to always face the direction the user is moving. This value will keep the map centered horizontally, but will show the location toward the bottom of the screen.
Setting AutoPanMode to CompassNavigation will always orient the map north. With these two AutoPanMode values of the LocationDisplay, you don’t even need to worry about the Rotation property from the last blog! How awesome is that?
Changing the symbology of the location marker is very simple. You can change the look of the CourseSymbol, HeadingSymbol (no doc link) or the DefaultSymbol. The CourseSymbol defines a symbol to use while location is actively changing. Great when using AutoPanMode.Navigation. The HeadingSymbol defines a symbol to be used when using AutoPanMode.CompassNavigation. And the DefaultSymbol defines the symbol to use when location is not changing.
<location:LocationDisplay IsEnabled="True" AutoPanMode="Default">
The awesomeness doesn't stop there. What happens when you need to test, or demo location functionalioty? Should you start walking outside? Enventually, sure. But the LocationDisplay also allows you to set a LocationProvider that should be used. This simple interface allows you to define when location changes, when the device orientation is changed, or the speed of travel has changed (or all of them at once). Many times you want to test location, but you are at your desktop. Plugging in a quick little ILocationProvider allows you to do your testing.
Note: Location works great on all three platforms, but compass orientation only works for Windows Store and Windows Phone apps because they have built in APIs for compass.
These features should compel you to use the ArcGIS Runtime SDK for your next mapping app. In the next post I’ll cover map pins within the SDK.