Note that post-Brexit the ONS no longer supply the 'Regional Authority' data (it's technically a European region, apparently), so MapIt can't supply it either. They stopped supplying it in May 2021. It is possible to use the previous 'generation' of data by using the 'generation' parameter set to 42. eg: https://mapit.mysociety.org/postcode/b24qa.html?generation=42. This is not implemented in this extension.
This extension looks up UK regional/political data from MapIt (https://mapit.mysociety.org/) and assigns it to custom fields. This allows you to search for everyone in particular regions, or Parliamentary Constituencies, and set up smart groups etc.
It looks up data in real time whenever a primary address is added or edited. Currently it looks up:
- Parliamentary Constituency
- Ward
- Highest Local Authority
- Second highest Local Authority
- Regional Authority (there are 12)
- Welsh Assembly Constituency
- Welsh Assembly Region
- Scottish Parliamentary Constituency
- Scottish Parliamentary Region
- UK Country
- requires full postcodes
- only works for postcodes (though there's some limited code in there for handling lat/long lookups in some situations specific to the BHA that you can customise)
- doesn't run when importing data, as MapIt is rate-limited to 1 per second and it'd take forever
- won't look up your existing data
and it's still fairly hacky, particularly in that the custom field values are hard-coded (sorry). But works!
Note: if pre-4.7.18 and using PayPal Pro, make sure to apply this PR first: https://github.com/civicrm/civicrm-core/commit/c9dbc47c1a676a05908675c9fe5a0b11f4562a79
- Install the extension.
- If you're a charity, sign up for a MapIt API key. As of writing it's free for 10,000 calls per month. You can use it for free without, though you get far fewer lookups. The extension will still work without an API key.
- Enter the API key at [normal Civi URL]/civicrm/mapit/settings
- Create Custom Fields for your desired data, and note their ID numbers
- Edit politicaldata.php and near the bottom you'll see a $customParams array where the data is assigned to whichever custom field. Edit the numbers in custom_xxx appropriately.
- Try editing a test record, then refresh the record. If you have an API key you can check on mapit to see whether the request was generated at all.
We'd love to see someone run with this! It really needs:
- Add an interface to assign custom fields
- Really needs a scheduled job to loop through imports / existing data look them up slowly
We filled in our existing records using a giant spreadsheet of doom from: https://geoportal.statistics.gov.uk/, then used MapIt for ongoing work.