Sunlight Labs
Project of The Sunlight Foundation    
Read the labs blog

SunlightLabs API

Your API keys

places.getLatLongsFromCityState

Get the latitude,longitude pairs from a city and state
There may be multiple (latitude,longitude) pairs, one per zipcode within the city

Arguments

These are all $_GET parameters.

city (required)

The city's full name

state (requried)

The two-letter state abbreviation

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

Example Call
http://api.sunlightlabs.com/places.getLatLongsFromCityState.php?city=College%20Park&state=MD
&apikey=23kj234kjb3kjbcl87ds

says give me the latitude,longitude pairs for College Park, MD

Example Response

The output is a JSON string with the data.

                  
{ "city" : "College Park", "state": "MD", 
	"latlongpairs": [ 
  	  { "latitude" : "38.997560", "longitude" : "-76.925770", "zip" : "20740" }, 
	  { "latitude" : "38.833563", "longitude" : "-76.877743", "zip" : "20741" }, 
	  { "latitude" : "38.833563", "longitude" : "-76.877743", "zip" : "20742" } 
	] 
}
For XML:
<results>
  <city>College Park</city>
  <state>MD</state>
  </latLongPairs>
    <latLongPair>
      <latitude>38.997560</latitude>
      <longitude>-76.925770</longitude>
      <zip>20740</zip>
    </latLongPair>
    <latLongPair>
      <latitude>38.833563</latitude>
      <longitude>-76.877743</longitude>
      <zip>20741</zip>
    </latLongPair>  
    <latLongPair>
      <latitude>38.833563</latitude>
      <longitude>-76.877743</longitude>
      <zip>20742</zip>
    </latLongPair>
  </latLongPairs>
</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

202: invalid combined user input data

The city+state was not valid