New Address to Congressional District API Method

by

Update (10/2010)


The method referenced here no longer exists, it is now recommended as a best practice to do the geocoding yourself (using Yahoo or Google’s free geocoding services) and then use the legislators.allForLatLong method in our API.


James Turk added a powerful address to congressional district method places.getDistrictFromAddress to the Sunlight Labs API. The method geocodes a street address using Google’s Map API and identifies the congressional district polygon in which the address’s lat/long falls using up-to-date shape files from Census.gov.

Here’s an example call:

http://api.sunlightlabs.com/places.getDistrictFromAddress?address=1818+N+St+NW+Washington,+DC&output=xml

Here’s an example result in XML (json also available):

<results>
<address>1818 N St NW Washington, DC</address>
<latitude>38.907231</latitude>
<longitude>-77.042149</longitude>
<districts>
<district state="DC">98</district>
</districts>
</results>

When I started at Sunlight Labs in 2006, I heard companies paying annual fees for zipcode to congressional district translation databases and services. This should no longer be the case, at least for small doses of information. First, we are offering this API method. Second, our service uses official congressional district political boundaries now being (or by 2008 will be) updated in real-time by the Census as they learn of changes. So it should be possible for others to code such a service as well. The only cost should be related to number of addresses needing to be coded. Google reasonably imposes 15,000 calls-per-day limitation from same IP address on its service. So we might look into an alternate geocoding service so we can scale. Then again, we might also just fire up instances of EC2 to source the calls from different IP addresses, too.