Bing Maps Task

You’ve seen in previous Windows Phone Mini-tutorials STATUE of Libertythat all tasks have the same basic structure:

  • Instantiate the task
  • Add any specifying data
  • Show the task

The Bing Maps Task is no different. In fact, it is so simple to use I hesitate to dedicate a mini-tutorial to it.  This will be brief.

To find a specific location using Bing Maps, all you need do is create a new Windows Phone application.  Set the Page and Application title and create a new row into which you’ll place a button (all of this is optional, but it makes the program easier to work with). 

Name the new button FindSiteButton and give it an event handler on its click event, as shown here:

<StackPanel
    x:Name="TitlePanel"
    Grid.Row="0"
    Margin="12,17,0,28">
    <TextBlock
        x:Name="ApplicationTitle"
        Text="Bing Maps"
        Style="{StaticResource PhoneTextNormalStyle}" />
    <TextBlock
        x:Name="PageTitle"
        Text="Find"
        Margin="9,-7,0,0"
        Style="{StaticResource PhoneTextTitle1Style}" />
</StackPanel>

<!--ContentPanel - place additional content here-->
<Grid
    x:Name="ContentPanel"
    Grid.Row="1"
    Margin="12,0,12,0">
    <Grid.RowDefinitions>
        <RowDefinition
            Height="96*" />
        <RowDefinition
            Height="511*" />
    </Grid.RowDefinitions>
    <Button
        Name="FindSiteButton"
        Content="Find"
        HorizontalAlignment="Center"
        VerticalAlignment="Center"
        Click="FindSiteButton_Click" />
</Grid>

Since you put the event handler into the Xaml, you’ll find a stub for that method in the code behind.  Switching to MainPage.xaml.cs, let’s fill in that event handler.

We do so by adding an instance of BingMapsTask (which you’ll need to add the using statement,

using Microsoft.Phone.Tasks;

 

Set the SearchTerm property of this task to a famous location and then, as with all tasks, call show:

private void FindSiteButton_Click( 
    object sender, RoutedEventArgs e )
{
    BingMapsTask bmt = new BingMapsTask();
    bmt.SearchTerm = "Statue of Liberty";
    bmt.Show();
}

 

Now run the emulator, click the button and you will see that Bing Maps instantly displays a map with the Statue of Liberty pin-pointed.

About Jesse Liberty

Jesse Liberty has three decades of experience writing and delivering software projects and is the author of 2 dozen books and a couple dozen online courses. His latest book, Building APIs with .NET will be released early in 2025. Liberty is a Senior SW Engineer for CNH and he was a Senior Technical Evangelist for Microsoft, a Distinguished Software Engineer for AT&T, a VP for Information Services for Citibank and a Software Architect for PBS. He is a Microsoft MVP.
This entry was posted in Essentials, Mango, Mini-Tutorial, Patterns & Skills, WindowsPhone and tagged . Bookmark the permalink.

4 Responses to Bing Maps Task

Comments are closed.