X90B: Bing Map Win Phone 7 Push Pins, fast and easy

X90B: Bing Map Win Phone 7 Push Pins, fast and easy

  • Comments 1

Ok, got the poop from the pros in Redmond on how to work with pushpins, it’s easy.  But wait, I need to make it really hard to understand and confusing.  After all it seems like everyone who writes a blog about Win Phone 7 and bing maps must make it so confusing and difficult that NO ONE can possibly understand it who is less than a “300” level, whatever that is. (It is a rating that training centers give their class material.)

You can download my sample application from (link verified as of Nov. 15, 2010), this sample has the XAML Pages in it, but it needs work.

http://bit.ly/winphonebingpushpins 

Thanks to Derrick Quan, the following code will get you working immediately, as long as you add pages to match the pages in the click events:

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Device.Location;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Controls.Maps;

//Your project will have a different namespace, so make sure to change the “YourWinPhoneMapApplication”

namespace YourWinPhoneMapApplication

{
    public partial class MainPage : PhoneApplicationPage
    {

        public MainPage()
        {
            InitializeComponent();

            this.Loaded += new RoutedEventHandler(MainPage_Loaded);
        }

        void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            Map map = new Map();
            map.CredentialsProvider = new ApplicationIdCredentialsProvider("Put your Bing Map API here");

            Pushpin pin1 = new Pushpin();
            pin1.Location = new GeoCoordinate(33.0, -117.0);
            pin1.Content = "1";
            pin1.MouseLeftButtonUp += new MouseButtonEventHandler(pin1_MouseLeftButtonUp);
            map.Children.Add(pin1);

            Pushpin pin2 = new Pushpin();
            pin2.Location = new GeoCoordinate(33.1, -117.0);
            pin2.Content = "2";
            pin2.MouseLeftButtonUp += new MouseButtonEventHandler(pin2_MouseLeftButtonUp);
            map.Children.Add(pin2);

            Pushpin pin3 = new Pushpin();
            pin3.Location = new GeoCoordinate(33.2, -117.0);
            pin3.Content = "3";
            pin3.MouseLeftButtonUp += new MouseButtonEventHandler(pin3_MouseLeftButtonUp);
            map.Children.Add(pin3);

            Pushpin pin4 = new Pushpin();
            pin4.Location = new GeoCoordinate(33.3, -117.0);
            pin4.MouseLeftButtonUp += new MouseButtonEventHandler(pin4_MouseLeftButtonUp);
            pin4.Content = "4";
            map.Children.Add(pin4);

            map.SetView(LocationRect.CreateLocationRect(pin1.Location, pin2.Location, pin3.Location, pin4.Location));
            ContentPanel.Children.Add(map);
        }

        void pin1_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            NavigationService.Navigate(new Uri("/YouMakeThisPage1.xaml", UriKind.Relative));
        }

        void pin2_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            NavigationService.Navigate(new Uri("/Youmakeanotherpage.xaml", UriKind.Relative));
        }

        void pin3_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            NavigationService.Navigate(new Uri("/Andanotherpagemadebyyou.xaml", UriKind.Relative));
        }

        void pin4_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            NavigationService.Navigate(new Uri("/Aforurthpagemadebyyou.xaml", UriKind.Relative));
        }

    }
}

 

That’s it, end of secret communications, for the 5 or 6 people who are reading this blog, I hope you share it with people you know.

NNNN

Leave a Comment
  • Please add 7 and 7 and type the answer here:
  • Post
  • with  icon ?????

Page 1 of 1 (1 items)
Generic Content

Legal Note:

  1. The author, Sam Stokes, is an employee of Microsoft
  2. There is no guarantee that anything I write is correct, I do try to make sure that what I write is correct.
  3. Use anything written in this blog at your own risk
  4. Test what I write about before using the information
  • Sometimes posts will disappear because I realized that they really don't fit with the total chaos of what I write about
  • Links are tested and available on date of publication, what others do with their links are out of my control

Restrictions:

  • Whatever I write on this blog is unedited by management or anyone, which should be obvious from the randomness of the blog.  I simply write about things I like.
  • Microsoft does not restrict me in anyway, so I generallyblather about whatever I want to.
  • For personal reasons I will not write about:
    • Company confidential stuff, mainly because Microsoft is more transparent than any company I have ever worked for.
    • Other people unless they give me permission to write about them