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

http://dev.virtualearth.net/webservices/v1/geocodeservice/geocodeservice.svc

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

https://nishantrana.wordpress.com/2011/03/05/using-bing-maps-silverlight-control/

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.Credentials.ApplicationId=((ApplicationIdCredentialsProvider)myMap.CredentialsProvider).ApplicationId;
    myGeoCodeRequest.Query = Address;

    // Pass the request to GeocodeAsyn method
    myGeoCodeClient.GeocodeAsync(myGeoCodeRequest);

}

void myGeoCodeClient_GeocodeCompleted(object sender, GeocodeCompletedEventArgs e)
{
    // create a map layer
    MapLayer myMapLayer = new MapLayer();
    myMap.Children.Add(myMapLayer);

    // 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
        myLocationColl.Add(myPushPin.Location);
        // Add the drawn point to the route layer.                   
        myMapLayer.Children.Add(myPushPin);
    }
    var bounds = new LocationRect(myLocationColl);
    myMap.SetView(bounds);
}
}

 

This is how it looks 


Bye.


Discover more from Nishant Rana's Weblog

Subscribe to get the latest posts sent to your email.

Unknown's avatar

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. 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?

    Regards,

    Erwin

    Like

  2. 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

    Like

Leave a reply to Clayton Lafleur Cancel reply

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

Discover more from Nishant Rana's Weblog

Subscribe now to keep reading and get access to the full archive.

Continue reading

Power Platform Puzzles

D365 CRM, Power Platform Tips &Tricks

Power Spark

Power Spark By Shrangarika

Van Carl Nguyen

Exploration of Power Platform

My Trial

It is my experience timeline.

Power⚡Thomas

Sharing my knowledge and experience about the Microsoft Power Platform.

Arpit Power Guide

a guide to powering up community

Welcome to the Blog of Paul Andrew

Sponsored by Cloud Formations Ltd

Deriving Dynamics 365

Deriving Solutions and features on Power Platform/Dynamics 365

The CRM Ninja

Thoughts & musings from a Microsoft Business Applications Ninja!

D CRM Explorer

Learn about Microsoft Dynamics CRM Power Platform customization and implementation and other cool stuffs

Stroke // Jonas Rapp

I know pre-stroke. I will improve who I was.

Power Melange

Power Melange By Shalinee

Clavin's Blog - PPUG.ORG

AI - Power Automate - Power Apps - SharePoint Online - Azure - Nintex - K2 - Artificial Intelligence

Sat Sangha Salon

An Inquiry in Being

The Indoencers

The Influencers & Influences of Indian Music

Monika Halan's blog

Hand's-free money management

D365 Demystified

A closer look at Microsoft Dynamics 365.

Microsoft Mate (msftmate) - Andrew Rogers

Experienced consultant primarily focused on Microsoft Dynamics 365 and the Power Platform

Manmit Rahevar's Blog

One Stop Destination for Microsoft Technology Solutions

MG

Naturally Curious

Brian Illand

Power Platform and Dynamics 365

Steve Mordue

The Professional Paraphraser

Subwoofer 101

Bass defines your home theater

SQLTwins by Nakul Vachhrajani

SQL Server tips and experiences dedicated to my twin daughters.

Everything D365

Discovering Azure DevOps and D365 Business Applications

Tech Wizard

Lets do IT Spells

XRM Tricks (Power Platform & Dynamics CRM )

Power Platform & Dynamics CRM

CRM TIPS BY PRM

Mail to crmtipsbyprm@gmail.com for queries and suggestions

nijos.dev

Giving back to the community what I have learned

Power Platform Learning

Your Go-To Resource for Power Apps, Power Automate & More

xrm CRM Dynamics

Dynamics CRM Technical & Functional Info

Dynamics 365 Blogs - Explained in unique way

Sometimes you need to look at things from different perspective.