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.

Share

The computer thinks these might be related:
  1. Windows Phone Fundamentals–3 Ways To Handle Events
  2. BingMapsTask in Mango
This entry was posted in Essentials, Mango, Mini-Tutorial, Patterns & Skills, WindowsPhone and tagged . Bookmark the permalink.

2 Responses to Bing Maps Task

  1. Lucky says:

    Hi , Thanks for tutorial , is was great . i want to ask , How can i send my lat. and log. to a server and a service that store it and other client can receive it , ?

  2. Jason says:

    Great new feature. This definitely makes working with the mapping api much easier for simple tasks.

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>