we use civicrm for a political org, and I'm trying to find out how to add voter district information to contacts in database.

The state doesn't have a public API from what I can tell. They have this website: http://whosmy.virginiageneralassembly.gov/, but getting the info out of this site would require some python scripting, and I don't know how to automate the export and reimport of the contact records.

There are KML files available from the census (https://www.census.gov/geo/maps-data/data/kml/kml_sld.html) that provide the boundaries for the districts. I'm wondering if anyone has advice on modules or approaches to take a contact's geocode address and determine which district boundary it falls in.



2 Answers 2


Google’s Civic Information API returns information about federal, state, local governments, school districts, etc. It takes as input an address string (not a lat/long pair). An API key is needed, but it’s free to obtain and use. In what little experimenting I’ve done recently, average latency has been ~350 ms.


I can share some experience from such a project a few years back. It required a fair bit of custom code implemented for that site, but ultimately your task would boil down to something like:

  • Identify contacts who you want to look up (eg, contacts with a state of VA and who don't already have custom data in custom field "District").
  • For each contact, ensure they meet minimum criteria (eg try geocoding the address first, do what you need to handle contacts whose address does not)
  • Once you have lat/long for the contact, look them up in a service capable of returning a value for the district. Options here vary - we used Koordinates originally (accepts KML, lets you query against it), but there are other options and that project eventually switched to an SQL approach.
  • Store the results of this lookup against the contact.

Other considerations -

  • How fast do you need to look up all the voters, and how performant is the lookup method? Do you need to invest time up front in mapping addresses to districts, or will a web service like Koordinates save you dev time/expense and let you work through the number of voter contacts required?
  • Does every contact's default address map to their voter registered address / are there cases where you have an address on file that doesn't map to their voting district? How do you handle these?
  • Do you want to permit "custom" values, eg "Bob is special, don't overwrite the district he's associated with because he chairs a neighbouring district" etc.
  • What happens when district boundaries change?

This isn't a built-in functionality and I'm not aware of a published extension.

  • <promo> If you want to discuss implementation, I'm sure you can track me or my employer Fuzion down :) ... if anyone finds this comment too advertorial, downvote it and I'll remove it ASAP! Commented Jan 17, 2017 at 21:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.