Automating the Windows Map App

Windows allows a Windows Store application to register as the default handler for a certain URI schema. This process is called Protocol Activation and it can be leveraged in the WinRT as well as the WinJS framework.

The Windows Map app is registered for protocol activation and the URI schema is documented here. Through protocol activation you can control the map view, find places or business listings, calculate routes or even map entire collections of points of interest.


In this quick example we leverage this capability to display the location where you captured a photo. Rather than starting from the scratch we build upon the Simple Image Sample from the Windows Dev Center. The first scenario in this application reads and writes properties of an image – including the coordinates (latitude and longitude) where we captured the photo.


There are a few changes that we need to apply to this app in order to launch the Map app and center on this location.

In the application markup language of scenario 1 we

  1. replace the boxes for degrees, minutes and seconds as well as the one for the compass orientation with a single text-box in which we will display the latitude and longitude in decimal degrees.
  2. add a button that will launch he map app with parameters.

The new XAML will look like this:

<TextBlock Grid.Column="0" Grid.Row="6" TextWrapping="Wrap" 
           Style="{StaticResource BasicTextStyle}" 
           HorizontalAlignment="Left" VerticalAlignment="Center">Latitude
<TextBox Grid.Column="1" Grid.Row="6" Margin="0,0,10,10" x:Name="LatTextbox" 
         HorizontalAlignment="Left"  Text="" Width="300" />

<TextBlock Grid.Column="0" Grid.Row="7" TextWrapping="Wrap" 
           Style="{StaticResource BasicTextStyle}" 
           HorizontalAlignment="Left" VerticalAlignment="Center">Longitude</TextBlock>
<TextBox Grid.Column="1" Grid.Row="7" Margin="0,0,10,10" x:Name="LonTextbox" 
         HorizontalAlignment="Left" Text="" Width="300" />

<Button x:Name="myPhotoLoc" Grid.Column="1" Grid.Row="8" 
        Click="myPhotoLoc_Click" Width="300" Margin="0,0,10,0" >Open Map</Button>

Next we look at the code behind and in the function GetImagePropertiesForDisplay we replace the code which splits the coordinates in degrees, minutes and seconds with the snippet below.

' Do a simple check if GPS data exists.
If (m_imageProperties.Latitude.HasValue) AndAlso (m_imageProperties.Longitude.HasValue) Then
  LatText = Math.Round(m_imageProperties.Latitude.Value, 6).ToString
  LatTextbox.Text = LatText

  LonText = Math.Round(m_imageProperties.Longitude.Value, 6).ToString
  LonTextbox.Text = LonText
End If

We also introduce a new function to handle the click-event on our button and launch the Map app:

Private Async Sub myPhotoLoc_Click(sender As Object, e As RoutedEventArgs)
  ' Create the URI to launch from a string.
  Dim uri = New Uri("bingmaps:?collection=name.Photo%20Locations~point." + _
    LatText + "_" + LonText + "_My%20Photo&sty=a")

  ' Launch the URI.
  Dim success As Boolean = Await Windows.System.Launcher.LaunchUriAsync(uri)
End Sub

And that’s it. You’ll find the complete source code here.

Happy Mapping Smile


This entry was posted in Bing Maps, Windows Store and tagged , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s