task Congressional District by Street Address Using Google Maps API
Previously, I set up a form to automatically look up someone's congressional district and legislator by a provided ZIP code. It used the Sunlight Labs API along with a PHP class. The problem was that a given ZIP code can have multiple congressional districts. To further complicate matters, the Sunlight Labs data doesn't have the district information for every ZIP code. Given those constraints, using just the ZIP code would have meant a lot of code writing to create fall backs for a variety of scenarios. Sunlight Labs actually recommends against using ZIP codes to look up congressional districts despite the fact that they link to the very PHP class I used. Alas, I didn't see their guidance until after the first version was up and running and I submitted a "bug" report.
Today I went ahead and improved this form so that the lookup is now based on the user's full address. It works something like this...As soon as the person's address is entered (including their zip code), it is sent to the Google Maps API (in the background via AJAX). Then, the return geocoded address (latitude and longitude) is passed onto the Sunlight Labs API via the aforementioned PHP class. In return, I get an exact match on the congressional district for the provided address. Voila. In this case, the district info is added to the user's profile for later advocacy efforts.
After receiving requests for more details about my code and approach, I decided to add a simplified version to GitHub. Check it out and use it as you deem fit: https://github.com/technotarek/CongressionalDistrictLookUp