Bing Maps Geocoding Multiple Addresses

Hi Experts, I have a question regarding Bing Maps and its Silverlight SDK..

I want to be able to get a list of addresses from a database using WCF DATA SERVICE and get the addresses geocoded and passed into the Silverlight Bing Maps Control.

Working with one address at a time seems to work fine but how can I re-engineer the code so that I can input an array of addresses and the output is an array of coordinates which i can then bind to the Bing Maps Silverlight Control in the form of pushpins?

Thanks in advance for your assistance

ps: I have the wcf service to get the addresses already
===
This is what i have currently in MainPage.xaml.cs - As you can see it takes in one address
===

private void geocodeaddresses(string rawadd)
        {
                GeocodeRequest geocodeReq = new GeocodeRequest();

                //set the credentials using a valid bing maps key
                geocodeReq.Credentials = new Credentials();
                geocodeReq.Credentials.Token = myKey;

                //set the full address query
                geocodeReq.Query = rawadd;
                

                //set the options to only return high confidence results
                ConfidenceFilter[] filters = new ConfidenceFilter[1];
                filters[0] = new ConfidenceFilter();
                filters[0].MinimumConfidence = gecodeservice.Confidence.High;

                GeocodeOptions geocodeOptions = new GeocodeOptions();
                geocodeOptions.Filters = filters;

                geocodeReq.Options = geocodeOptions;

                GeocodeServiceClient geocodeService = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService");
                geocodeService.GeocodeCompleted +=new EventHandler<GeocodeCompletedEventArgs>(geocodeService_GeocodeCompleted);
                geocodeService.GeocodeAsync(geocodeReq);
}

 void geocodeService_GeocodeCompleted(object sender, GeocodeCompletedEventArgs e)
        {

            GeocodeResponse geoResp = e.Result;
}

Open in new window

baz86Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Kevin CrossConnect With a Mentor Chief Technology OfficerCommented:
Maybe you don't need to re-engineer, but rather wrap the solution you have by creating a new method that takes in an array|list of string addresses. You can iterate the array and pass the separate address strings to the Bing Maps web service function you already have written to handle one geocode. Collect the responses back into a collection of geocodes and return it.
0
 
baz86Author Commented:
thank you mwvisa1 for your reply. Ah! so basically keep the geocode method as it is but then within another method call is several times within a loop or so and pass one address at a time?
0
 
Kevin CrossChief Technology OfficerCommented:
yes exactly. Now you have two methods available at your disposal without having to maintain main code twice. A good modular programming practice anyway...
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
baz86Author Commented:
I will award the points and try that! Thank You!
0
 
baz86Author Commented:
I will try the suggested solution.
0
 
Kevin CrossChief Technology OfficerCommented:
@baz86:

Glad you will try that out. Note you don't need to award points before you have tested, so please advise if you change your mind as I can request this be re-opened for you.

Otherwise, if it works, then best regards!

Kevin
0
 
baz86Author Commented:
Hi mxvisa1, just wanted to let you know that I did get the solution working!!Thanks! I created an array of the return type from the event args and called the method for each item within the list.
0
 
merwanchintaCommented:
HI,

Can you please provide me a sample. I didn't quite get your suggestion. I need to get Co-ordinates for N number of addresses in a single web service call. How to get it?

Please help me.

thanks,
0
 
Kevin CrossChief Technology OfficerCommented:
The suggestion was to have the web service call take in a collection of addresses and parse those to individual address entries which you then pass to a call to the bing maps API.  The response from the all will be the individual coordinates, but if you keep track of these in a second collection and return it as the response then you are set.  In this case the web service or code to get the coordinates for a single address was already done...if you don't already know how to do so, I would start a new related question!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.