I thought I would post this here not so much as a question but to share with the community some code I wrote after not being able to find the answer here on StackOverflow. If someone would like to take a look at the code and improve it, that would be great, but not required. I have left out some code (try-catch blocks & error handling) to make it a little bit easier to consume the concept and code.
Share
So, let’s start with the problem I needed to solve. I wanted to be able to allow someone to enter part or all of a city, state, zipcode combination and use Yahoo’s PlaceFinder API to figure out exactly where it was. Nothing fancy, just a simple way to resolve a city & state from a zip code or vice-versa.
This process involves:
Let’s start with the namespaces you’ll want to import:
Next, let’s look at constructing the request:
Next, we want to get the response and put it into an object model that makes it easy to work with:
But wait, there’s one last important piece missing. What is a ‘
YahooResponse‘ object? What does the class definition look like? Here is what I came up with:Read more about the PlaceFinder service here: http://developer.yahoo.com/geo/placefinder/guide/