Using GeoCode service to show addresses as PushPin(s) in Bing Map Silverlight Control.

For this first we need to add service reference to Geocode service to our Silverlight Application

On how to create Silverlight Application that uses Bing Map Control please refer to

Geocode service will return us the results found (locations) based on the address passed to it.

We can use the below sample code that displays the Pushpins on Bing Map based on the query (address) provided. (Here I am providing my permanent address)

public MainPage()
    InitializeComponent();    string Address = "759 Jantanagar, Chandkheda, Gandhinagar, Gujarat, 382424";
    GeocodeServiceClient myGeoCodeClient = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService");          
    // create an event hanler for GeocodeCompleted event as the service would be call asynchronously
    myGeoCodeClient.GeocodeCompleted+=new EventHandler<GeocodeCompletedEventArgs>(myGeoCodeClient_GeocodeCompleted);
    // create the request and pass the address to it
    GeocodeRequest myGeoCodeRequest = new GeocodeRequest();
    myGeoCodeRequest.Credentials = new Microsoft.Maps.MapControl.Credentials();
    myGeoCodeRequest.Query = Address;

    // Pass the request to GeocodeAsyn method


void myGeoCodeClient_GeocodeCompleted(object sender, GeocodeCompletedEventArgs e)
    // create a map layer
    MapLayer myMapLayer = new MapLayer();

    // create a location collection class
    LocationCollection myLocationColl=new LocationCollection();

    foreach (GeocodeResult gr in e.Result.Results)
        Pushpin myPushPin = new Pushpin();
        // set it to first found location
        myPushPin.Location = gr.Locations[0];
        // add it to location collection
        // which would be used to set the map's bound
        // Add the drawn point to the route layer.                   
    var bounds = new LocationRect(myLocationColl);


This is how it looks 



Author: Nishant Rana

I love working in and sharing everything about Microsoft.NET technology !

2 thoughts on “Using GeoCode service to show addresses as PushPin(s) in Bing Map Silverlight Control.”

  1. It dosen’t seem to work. I have looked at your code and tried to use it, but I keep getting an error. “Cannot implicitly convert type LocatingLocalSuppliers.GeocodeingService.GeocodeLocations to Microsoft.Maps.MapControl.Location.
    Is there a way to fix this


  2. Nice small article; I’m trying to do something similar, but step 1, adding a service reference will not succeed… (Custom tool error: Failed to generate code …. … )
    Could the reason be that I already use RIA services in my project?




Please share your thoughts

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.