Digital Colony!

Using Yahoo! Maps GeoCoding API in C#

Building a map using Yahoo! Maps or Google Maps requires Latitude and Longitude points. Until Yahoo! released it's GeoCoding APIs getting address latitude and longitude was neither easy or free. At this time Yahoo! allows you to GeoCode 50,000 addresses a day. The code below will call the Yahoo! GeoCoding API using C# and ASP.NET 2.0. Yahoo!

Latitude and Longitude Precision

When supplying Yahoo! with an address, it will try to return the highest level of precision. The returned XML document will tell you how precise the latitude and longitude are. If it can't resolve an address, it will return a warning. Yahoo! Map

Files Included in Download

* GeoCode.aspx - Form to enter address. Also will display response from Yahoo!.
* GeoCode.aspx.cs - Calls class to make geocoding request.
* GeoAddress.cs - An address class.
* GeoAddressAPI.cs - Class which calls Yahoo! and parses response.
* web.config - Holds application ID required by Yahoo!

GeoCode.zip - Don't forget to enter your application ID at the end of the querystring in the web.config file. This format supports ASP.NET 2.0. If you are running 1.1, you will need to make some minor adjustments to how you store your API url in the web.config file.

Working Demo

GeoCoding C# Yahoo Demo

Labels: , , ,

AddThis Social Bookmark Button

22 Comments:

Anonymous Anonymous said...

This is an awesome article using microsoft technologies. Since it has the geocoding and is a complete solution.

Thanks for your harwork.

2/20/2007 4:32 PM

Anonymous Dave said...

I downloaded the demo, but I'm getting this error when I try to run:

CS0246: The type or namespace name 'GeoAddressAPI' could not be found (are you missing a using directive or an assembly reference?)

Could you help me out?

Dave

3/27/2007 1:23 PM

Blogger MAS said...

Dave --
Place the .cs files in a folder named "App_Code" and that error should go away. I'll update the .ZIP file later.

3/27/2007 1:29 PM

Anonymous Dave said...

OK, that did it. Thanks!

3/27/2007 1:52 PM

Anonymous Anonymous said...

I used my yahoo app id(id applied using different website from my map Application), get the error, please tell what's wrong.
Error Message: The remote server returned an error: (407) Proxy Authentication Required.

7/16/2007 2:02 PM

Blogger MAS said...

Apply for a new ID and see if that fixes the problem. I could not replicate that error.

7/16/2007 3:33 PM

Anonymous Anonymous said...

I'm getting the following error:

Could not find a part of the path 'c:\windows\system32\inetsrv\asdasd\&zip=24060'.


Does this have something to do with the XPath Prefixing? How do I go about fixing this?

Thanks

David

8/11/2007 1:43 PM

Blogger MAS said...

David,
You need to add the apiURL key to your Web.Config.

... add key="apiURL" value="http://api.local.yahoo.com/MapsService/V1/geocode?appid=Your-ID-Here"

8/11/2007 2:00 PM

Anonymous Anonymous said...

Great job. Thanks!

11/20/2007 7:58 AM

Blogger BonGeek said...

Good one!

12/02/2007 1:15 AM

Blogger suhra said...

Thanks for this code. It worked fine for a while and then I started receiving error "The remote server returned an error: (403) Forbidden." I even got a new key but still had no luck.

Please help.

Thanks.

Suhra

1/25/2008 6:38 AM

Blogger MAS said...

Contact Yahoo or apply for a new number. Error Codes

1/25/2008 6:56 AM

Anonymous Anonymous said...

Nicely done, Thanks for sharing.

2/21/2008 4:50 PM

Blogger Tiger said...

I have test the demo. it is works great, but how do i make the marker on the map?
Thanks!

4/01/2008 2:26 PM

Blogger MAS said...

Making markers is documented over on Yahoo! Look for the demos for YGeoPoint.

4/01/2008 2:32 PM

Blogger Tiger said...

Thanks Mas! Thant was fast.
but there no maps images.
Have you using google map?

4/01/2008 2:38 PM

Blogger MAS said...

I found when I first started using maps that Yahoo! was more developer friendly, whereas Google was more user friendly. It's been a year since I looked at either one.

Yahoo! does have forums to help developers. Best of luck.

4/01/2008 2:40 PM

Blogger Tiger said...

thanks mas, I get it, there some example to use AJAX map

4/01/2008 2:54 PM

Blogger padu said...

How can i find appid in
GeoZip?

5/02/2008 1:43 AM

Blogger MAS said...

The AppID is something issued by Yahoo! and it is entered in the web.config.

5/02/2008 6:49 AM

Anonymous Anonymous said...

Hi mas,

I have few doubt that need to clarify from you.

1.) How/Where can I find appid in
GeoZip?

2.) When I build the code, it prompt 2 error message

error1
------
"It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS. - Web.Config"

error2
------
"C:\Inetpub\wwwroot\geocode\App_Data\GeoCode.aspx: ASP.NET runtime error: It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS. (C:\Inetpub\wwwroot\geocode\app_data\web.config line 28) - GeoCode.aspx"

Please advice.

Million thanks.


Regards,
Kee

5/07/2008 3:26 AM

Blogger MAS said...

Kee - your errors are unrelated to this project. It sounds like an IIS issue, which is outside the scope of this article.

AppID is issued by Yahoo and appended to the value URL for apiURL in appSettings of the Web.Config.

5/07/2008 8:43 AM

 

Post a Comment

 

Digital Colony Copyright © 1999-2008 XHTML   508
This site uses Blogger, which is not 100% XHTML compliant.
Try...Catch Disclaimer: For brevity many examples do not include error handling. That is your responsibility.