Mobile Commons has built a database of state and congressional legislators that you can look up by latitude and longitude.

There are two parts:

  • An open source application that you can run yourself
  • A public service hosted by Mobile Commons you can access with our API

Description

Mobile Commons has amazing tools for launching advocacy campaigns using mobile technology. One of the most cost-effective ways to generate calls to action is mConnect, our product that let you send out a broadcast text message with an embedded phone number. Users can reply CALL and their phone rings a second later. First they hear audio talking points (that you can upload or call in and record), then they are transferred to a destination.

In the commercial world, users are often connected to sales agents or call centers. In the advocacy space, our customers want to connect people to their legislators. Wouldn’t it be cool if users were automatically routed directly to their legislators without having to go through the congressional switchboard?

From this need, we built a database of congressional and state legislators that you can query by latitude and longitude. We use this database to send targeted messages to specific legislative districts. We also use it to automatically route callers directly to their legislators.

Open Source Application

The database is available as a standalone application that you can download and run yourself. It is built using Ruby and Rails and uses a Postgres database with PostGIS extensions.

The code is hosted on GitHub and is available under an MIT open source license.

The shapefiles are taken from census.gov. Be aware that the shapefiles do change; we will update our code whenever the district shapefiles change, but it will be your responsibility to pull in the new versions to keep your service up to date.

Detailed installation instructions can be found in the README file of the project.

Hosted Version

While it’s nice to have the source code and data files available, we realize that it’s not always trivial or cost-effective to run software on your own servers and, more importantly, keep it up to date. Mobile Commons is pleased to provide a hosted version that you can access with an API.

We made the database publicly available as a web service at http://congress.mcommons.com.

Congressional lookup is available in a number of formats:

  • An HTML version with a Google Map and geocoder
  • XML
  • KML
  • GeoRSS

A query for a latitude and longitude:
http://congress.mcommons.com/districts/lookup.xml?lat=40.7145248&lng=-74.007073

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<?xml version="1.0" encoding="UTF-8"?>
<response>
  <lat>40.7145248</lat>
  <lng>-74.007073</lng>
  <federal>
    <state>NY</state>
    <district>8</district>
    <display_name>NY 8th</display_name>
  </federal>
  <state_lower>
    <state>NY</state>
    <district>066</district>
    <display_name>NY 66th</display_name>
  </state_lower>
  <state_upper>
    <state>NY</state>
    <district>025</district>
    <display_name>NY 25th</display_name>
  </state_upper>
</response>

Pastie #337868 linked directly from Pastie.

 

If no latitude and longitude is supplied:
http://congress.mcommons.com/districts/lookup.xml

1
2
3
4
5
6
<?xml version="1.0" encoding="UTF-8"?>
<response>
  <lat></lat>
  <lng></lng>
  <error>Must supply lat and lng parameters</error>
</response>

Pastie #337850 linked directly from Pastie.

 

If the latitude and longitude is outside of the United States, and does not match
any legislative district geographies:
http://congress.mcommons.com/districts/lookup.xml?lat=64.835054&lng=147.646528

1
2
3
4
5
6
<?xml version="1.0" encoding="UTF-8"?>
<response>
  <lat>64.835054</lat>
  <lng>147.646528</lng>
  <error>No district found</error>
</response>

Pastie #337847 linked directly from Pastie.

Notes

Join our low volume mailing list for advance notice of API changes or to ask a question.

We also wrote an open-source Ruby client library that you can use.

Please note that we do not provide any geocoding capabilities in our API at this time. The input to our API is a latitude and longitude. It is your own responsibility to geocode any addresses that you may want to look up. For inexpensive solutions, we recommend looking at Google, Yahoo, or Geocoder.us.

The HTML demo version does have a form that lets you enter a single address and convert it to latitude and longitude. This is provided by the Google Map Javascript API and cannot be used for production code.