Click here to Skip to main content
15,891,905 members
Articles / Mobile Apps / Windows Phone 7

Bing Maps in Windows Phone

Rate me:
Please Sign up or sign in to vote.
3.60/5 (6 votes)
9 Nov 2012CPOL1 min read 39.2K   1.5K   7  
Using Bing Maps in Windows Phone 7
// Houssem Dellai  
// houssem.dellai@ieee.org  
// +216 95 325 964  
// Studying Software Engineering  
// in the National Engineering School of Sfax (ENIS)  

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

namespace BingMapsDemoV1
{
    public partial class MainPage : PhoneApplicationPage
    {

        // Constructor
        public MainPage()
        {
            InitializeComponent();

            map1.CredentialsProvider = new ApplicationIdCredentialsProvider("Asa2x7ZzhYIHauji6TzIkcf3TIDznTgBaPKQehsyE4taOz19Mx4fP4lyihqbTj7D");
        }

        private void zoomIn_click(object sender, EventArgs e)
        {
            map1.ZoomLevel++;
        }

        private void zoomOut_click(object sender, EventArgs e)
        {
            map1.ZoomLevel--;
        }

        private void chooseMyPosition_click(object sender, EventArgs e)
        {
            NavigationService.Navigate(new Uri("/ChooseMyPosition.xaml", UriKind.Relative));
        }

        private void Aerial_click(object sender, EventArgs e)
        {
            map1.Mode = new AerialMode(true);
        }

        private void Road_click(object sender, EventArgs e)
        {
            map1.Mode = new RoadMode();
        }

        private void locateMe_click(object sender, EventArgs e)
        { 
            Pushpin p = new Pushpin();
            p.Background = new SolidColorBrush(Colors.Yellow);
            p.Foreground = new SolidColorBrush(Colors.Black);
            p.Location = new GeoCoordinate(SharedInformation.myLatitude, SharedInformation.myLongitude);
            p.Content = "I'm here";
            map1.Children.Add(p);
            map1.SetView(new GeoCoordinate(SharedInformation.myLatitude, SharedInformation.myLongitude, 200), 9);
        }

        private void setPin_click(object sender, EventArgs e)
        {
            NavigationService.Navigate(new Uri("/PushpinProperties.xaml", UriKind.Relative));
        }

        private void addPin_click(object sender, EventArgs e)
        {
            Pushpin p = new Pushpin();
            p.Background = new SolidColorBrush(Colors.Blue);
            p.Foreground = new SolidColorBrush(Colors.White);
            p.Location = new GeoCoordinate(SharedInformation.pinLat, SharedInformation.pinLong);
            p.Content = SharedInformation.pinContent;
            map1.Children.Add(p);
        }

    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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


Written By
Software Developer Microsoft
Tunisia Tunisia
I'm a Software Engineer and MVP (Client Development). I like writing articles and developing open source software in C#, Windows Phone and Windows 8 applications droidcon.tn/speakers.php.
http://houssemdellai.net

Comments and Discussions