Click here to Skip to main content
Click here to Skip to main content

Bing Maps in Windows Phone

By , 9 Nov 2012
 

Introduction

Nowadays, mobile applications are getting more and more successful. Their most important advantage is mobility which is realized thanks to some features like Bing Maps. That allows them to be more dynamic and gives a lot of appreciated services to customers. Bing Maps could help find the user's location and show him roads and distances. 

Using the code   

This app will shows you how to use the Map control under the Toolbox. After you drag and drop it on the page, you will have the following code added in the .xaml file.  

<my:Map Height="543" HorizontalAlignment="Left" 
  Name="map1" VerticalAlignment="Top"
  Width="480" Margin="-12,0,0,0" />

After that we will need to add the following usings to start using the Map features:

using Microsoft.Phone.Controls;
using Microsoft.Phone.Controls.Maps;
using System.Device.Location;

So now you can manipulate map1 from the .cs file. We are going to add a simple Pushpin using this code:

//declare the Pushpin 
Pushpin p = new Pushpin();
//define it's graphic properties 
p.Background = new SolidColorBrush(Colors.Yellow);
p.Foreground = new SolidColorBrush(Colors.Black);
//where to put the Pushpin 
p.Location = new GeoCoordinate(10, 36);
//What to write on it
p.Content = "You are here";
//now we add the Pushpin to the map
map1.Children.Add(p);
map1.SetView(new GeoCoordinate(10, 36, 200), 9); 

I added some icons to use it Zoom In, Zoom Out, use the Road Mode and the Aerial Mode with labels:

<phone:PhoneApplicationPage.ApplicationBar>
    <shell:ApplicationBar IsVisible="True" IsMenuEnabled="True" Opacity="0.9">
        <shell:ApplicationBarIconButton IconUri="/Icons/plus.png" Text="Zoom In" Click="zoomIn_click"/>
        <shell:ApplicationBarIconButton IconUri="/Icons/minus.png" Text="Zoom out" Click="zoomOut_click"/>
        <shell:ApplicationBarIconButton IconUri="/Icons/A.png" Text="Aerial mode" Click="Aerial_click"/>
        <shell:ApplicationBarIconButton IconUri="/Icons/R.png" Text="Road mode" Click="Road_click"/>
        <shell:ApplicationBar.MenuItems>
            <shell:ApplicationBarMenuItem Text="Choose my position" Click="chooseMyPosition_click"/>
            <shell:ApplicationBarMenuItem Text="Locate Me" Click="locateMe_click"/>
            <shell:ApplicationBarMenuItem Text="Set Pushpin" Click="setPin_click"/>
            <shell:ApplicationBarMenuItem Text="Add Pushpin" Click="addPin_click"/>
        </shell:ApplicationBar.MenuItems>
    </shell:ApplicationBar>
</phone:PhoneApplicationPage.ApplicationBar>  

This line of code is for navigating between pages:

NavigationService.Navigate(new Uri("/ChooseMyPosition.xaml", UriKind.Relative)); 

Some snapshots:

If you need any more information about it, please let me know. 

You may want to see my other samples on MSDN here.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Houssem_Dellai
Student
Tunisia Tunisia
Member
I'm studying Software Engineering. I like writing articles and developing open source software in C#, Windows Phone and Windows 8 applications http://bit.ly/WpZFWC. I enjoy giving training sessions about .NET technologies. I enjoy talking on international conferences about software technologies http://droidcon.tn/speakers.php.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralMy vote of 5memberEdward Keningham9 Aug '12 - 13:52 
Question[My vote of 2] No article contentmemberGanesanSenthilvel9 Aug '12 - 6:25 
AnswerRe: [My vote of 2] No article contentmvpSandeep Mewara12 Aug '12 - 9:04 
GeneralMy vote of 4memberChristian Amado9 Aug '12 - 6:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web02 | 2.6.130523.1 | Last Updated 9 Nov 2012
Article Copyright 2012 by Houssem_Dellai
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid