To use the Map control, begin by ensuring that the ID_Cap_Map capability is selected in the project’s WMAppManifest.xml file. Without the capability, an exception is raised at runtime.
Adding a Map control to a page requires a namespace definition at the top of the page, as shown:
xmlns:m="clr-namespace:Microsoft.Phone.Maps.Controls;
assembly=Microsoft.Phone.Maps"
An m:Map
element can then be placed somewhere on your host page, like so:
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<m:Map Loaded="HandleMapLoaded" />
</Grid>
The Map
control requires an API key to function in production. The Map
object’s Loaded
event is used to populate an application ID and an authentication token value, via the static ApplicationContext
property of the MapsSettings
class, as shown:
void HandleMapLoaded(object sender, RoutedEventArgs e)
{
MapsSettings.ApplicationContext.ApplicationId = "<applicationid>";
MapsSettings.ApplicationContext.AuthenticationToken
= "<authenticationtoken>";
}
You do not need the API keys during development of your app. The Loaded
handler can be left in your code during development. Invalid ApplicationId
and AuthenticationToken
values do not affect or disable the Map
control during development. Valid keys are required for production, however.
18.221.89.18