Solved

Bing Maps Geocoding Multiple Addresses

Posted on 2010-08-14
9
1,736 Views
Last Modified: 2012-05-10
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

0
Comment
Question by:baz86
  • 4
  • 4
9 Comments
 
LVL 59

Accepted Solution

by:
Kevin Cross earned 500 total points
Comment Utility
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
 

Author Comment

by:baz86
Comment Utility
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
 
LVL 59

Expert Comment

by:Kevin Cross
Comment Utility
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
 

Author Comment

by:baz86
Comment Utility
I will award the points and try that! Thank You!
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Closing Comment

by:baz86
Comment Utility
I will try the suggested solution.
0
 
LVL 59

Expert Comment

by:Kevin Cross
Comment Utility
@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
 

Author Comment

by:baz86
Comment Utility
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
 

Expert Comment

by:merwanchinta
Comment Utility
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
 
LVL 59

Expert Comment

by:Kevin Cross
Comment Utility
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

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now