Sunlight Labs
Project of The Sunlight Foundation    
Read the labs blog

SunlightLabs API

Your API keys

places.getDistrictFromLatLong

Get the congressional district from a latitude and longitude.

Arguments

These are all $_GET parameters.

latitude (required)

The latitude of the location to look up.

longitude (required)

The longitude of the location to look up.

apikey (required)

your individual API key

metadata (optional)

&metadata=true provides detail about source, last update of the information etc. Click here for details

output (optional)

&output=json is set by default. You can also use &output=xml

If you intend to do mass processing you may wish to use the polipoly library.

Example Call
http://api.sunlightlabs.com/places.getDistrictFromLatLong?latitude=40.6&longitude=-74.1&output=xml
&apikey=23kj234kjb3kjbcl87ds

says give me the congressional district that 40.6° N and 74.1° W (around NYC). (Note that longitude should be negative for the western hemisphere)

Example Response

For the default JSON:

{
 "latitude":"40.6", 
 "longitude":"-74.1", 
 "districts": [ {"state":"NY", "district":"13"} ] 
}
For XML:
<results>
  <latitude>40.6</latitude>
  <longitude>-75.1</longitude>
  <districts>
    <district state="NY">13</district>
  </districts>
</results>

Error Codes

If there is an error: a plain text string will be returned:

100: invalid API key

The API key was invalid

101: API key not valid for this method

Not permitted to call this particular method with this particular API key

306: Address does not fall within a congressional district

The address in question does not appear to fall within a district, ie. it is in a foreign country

311: Invalid Latitude

The latitude provided is invalid or empty.

312: Invalid Longitude

The longitude provided is invalid or empty.