Search code examples
c#bing-mapspushpin

Changing the Icon Style of my Pushpin


I have pushpins on my map in Visual Studio (below is the code that does this). But they are blue dots. I want to change my pushpins to something else besides blue dots. I found this website that gives a bunch of syntax of pushpins. (http://msdn.microsoft.com/en-us/library/ff701719.aspx) Currently, it displays the pushpin as number 77. I don't know if this is the default pushpin, or what. But I want to change it to something else like 71 so it gives more information. Any idea how I can do this with my code I have below? Thanks!! :)

    private async void PopulateMap()
    {
        //put data on map
        LocationCollection locationCollection = new LocationCollection();

        if (_group != null)
        {
            foreach (SampleDataItem item in _group.Items)
            {
                Pushpin myPushpin = new Pushpin();
                myPushpin.Text = item.Title;

                //created new location
                Location rentLocation = new Location(Convert.ToDouble(item.Latitude), Convert.ToDouble(item.Longitude));
                MapLayer.SetPosition(myPushpin, rentLocation);
                rentalMap.Children.Add(myPushpin);
                locationCollection.Add(rentLocation);

            }
        }

Solution

  • The documentation you referenced is for the Static imagery API and those pushpins are not available outside of that service. That said it's very easy to create custom pushpins. If you simply want to change the color try using the background property of the Pushpin class. Alternatively you can create a custom style that has a DataTemplate and apply that to the pushpin. If you simply want to use an image as a pushpin you can create an Image object, or any UIElement and add it to the map the same way you do a pushpin.

    I'm assuming you are creating a Windows 8 app. If so, take a look at my free ebook on crating location intelligent windows store apps. In chapter 4 I show how to create custom pushpins: http://rbrundritt.wordpress.com/my-book/

    You can also find all the code samples for the book here: http://code.msdn.microsoft.com/Location-Intelligence-for-1c691d0e