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

About Jesse Liberty

Jesse Liberty is an independent consultant and programmer with three decades of experience writing and delivering software projects. He is the author of 2 dozen books and multiple Pluralsight courses, and has been 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 Xamarin Certified Mobile Developer and a Xamarin MVP, Microsoft MVP and Telerik MVP.
This entry was posted in Essentials, Mango, Mini-Tutorial, Patterns & Skills, WindowsPhone and tagged . Bookmark the permalink.

4 Responses to Bing Maps Task

  1. Pretty nice post. I simply stumbled upon your weblog and wished to say that I’ve really enjoyed browsing your blog posts. In any case I will be subscribing for your rss feed and I hope you write once more very soon!

  2. Dann Carter says:

    Microsoft (MSFT) may be a bit behind Google (GOOG) and Apple (AAPL) when it comes to creating a voice-enabled personal assistant for its mobile devices, but it seems the company does have plans to add better speech recognition capabilities to its Bing mobile app in the near future. MSFTKitchen has posted a video demonstration of a new prototype for voice recognition software on Windows Phone devices that’s intended to show how Microsoft has worked to reduce latency and word recognition errors while improving phones’ ability to accurately hear you in crowded, noisy areas.”

    My favorite web site
    <.http://www.caramoan.co/caramoan-tour/

  3. 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 , ?

  4. 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.