Jerry Nixon @Work: Easily use Yahoo!’s Geocode Service in your Metro App

Jerry Nixon on Windows

Thursday, June 14, 2012

Easily use Yahoo!’s Geocode Service in your Metro App

imageIf you want to interact with a map, you will likely need latitude and longitude, not the string like “Denver, CO”. In order to convert a string into lat/long you need a geocoding service.

You might also have an address, like “123 Main Street”, and want to validate the address or standardize the address in your application. To do that, you need a geocoding service.

Yahoo PlaceFinder

Yahoo provides a nice geocoding service called Placefinder and developers can use this service in their applications quite easily.

Yahoo! PlaceFinder is a geocoding Web service that helps developers make their applications location-aware by converting street addresses or place names into geographic coordinates (and vice versa).

PlaceFinder recognizes a large number of place formats and returns rich geographic data about each result, including geographic coordinates, address components, and WOEID. The WOEIDs returned by the service can be passed to Yahoo!'s GeoPlanet API for further geographic enrichment and discovery.

First, get a key

Keys for Yahoo! services are easy to get. From what I can tell, most of their services are free for developers. And so is the developer key. So, navigate to here and get your key.

Second, copy my GeocodeHelper

Yes, it’s another helper class. Just add it to your project and you are good to go. Now, don’t read me wrong – you can write it from scratch like I did. Or you can copy mine. Or whatever, but here’s your fast onramp to get started and going today!

Get the code here.

Here’s the Helper’s API:

Constructor(s)

GeocodeHelper(key);

Example:

var _Helper = new GeocodeHelper(“youneedyourownkey”);

Method(s)

SearchAsync(query, type);

Example:
var _Results = async Search(“denver, co”);

Just like it is possible that the service will not find your string, it is also possible that it will find more than one (think apartments). Because of this, the results are enumerable.

Conclusion

This is just one of a series of helpers. Check them all out. Geocoding is powerful, and really important for mapping applications. You might be checking data entry. You might be pinning waypoints. Whatever it is, this should make it easy.

Best of luck!