Skip to content

Find your legislators by typing your address - #2391

Open
mvictor55 wants to merge 1 commit into
codeforboston:mainfrom
mvictor55:feature/address-legislator-lookup
Open

mvictor55 wants to merge 1 commit into
codeforboston:mainfrom
mvictor55:feature/address-legislator-lookup

Conversation

@mvictor55

Copy link
Copy Markdown
Collaborator

Summary

MAPLE currently sends people to the legislature's "find your legislator" tool and asks them to come back and pick their representative and senator. This adds an address box above those two pickers, on Edit Profile and on the "Select Your Legislators" step of submitting testimony. Type a home address, press "Find my legislators", and both pickers fill in. The pickers still work by hand, and the link to the legislature's tool stays as a fallback.

How it works (details in docs/legislator-address-lookup.md):

The browser sends the address to MassGIS's statewide geocoder, built on its statewide address points. The matched point is then looked up in MassGIS's official 2021 House and Senate district layers. Both services allow cross-origin requests, so no backend is needed and the address never reaches MAPLE's servers and isn't saved. The note under the box says so.
District names are matched to MAPLE's member search index (districtId from functions/src/districts/normalize.ts). The district layers also carry legislators' names, but those lag behind (one district still reads "Open"), so they aren't used. A district with no member in the index is shown as possibly vacant, and that picker is cleared.
Picking the right match (decideCandidate): the geocoder treats a town that shares its county's name (Worcester, Plymouth, Barnstable, Franklin, …) as matching every town in that county at the same score, and gives Boston addresses their neighborhood as the city. Matches in the town, neighborhood or ZIP code the user typed are therefore preferred. A single exact match is taken. Anything fuzzier (a corrected spelling, a different town) asks "Which of these is your address?". The matched address is always shown.

Behind a new flag, legislatorAddressLookup: on in development (dev site and previews) and off in production.

No new dependencies.

Checklist
[x] On the frontend, I've made my strings translate-able.
[x] If I've added shared components, I've added a storybook story. (The lookup renders inside the existing LegislatorForm story.)
[x] I've made pages responsive and look good on mobile. (Checked at 420px and 375px.)
[x] If I've added new Firestore queries, I've added any new required indexes to firestore.indexes.json. (No new queries.)
Screenshots

To be added: the found state (both pickers filled) and the "Which of these is your address?" state.

Known issues
Depends on MassGIS being up. If it doesn't answer, the user sees a message pointing to the legislature's tool.
Not compared against the legislature's own tool, which sits behind a CAPTCHA. Instead, 27 addresses across the state were run against the live MassGIS services, and the districts returned agreed 27 for 27 with the Census Bureau's 2026 state legislative district layers at the same points.
Redistricting. After the 2030 census, the layer URLs and the district-name fixture will need updating (see the doc).
Storybook shows vacancies. The LegislatorForm story's mock members have the district "District", so a lookup there reports both seats as possibly vacant. That's expected with the mock data.
Extra Deploy Steps
When releasing: set legislatorAddressLookup: true under production in components/featureFlags.ts. Until then the lookup can be tried on production with ?legislatorAddressLookup=enabled.
Steps to test/reproduce
On the preview, sign in and go to Edit Profile.
In "Your Legislators", type 24 Beacon St, Boston and press "Find my legislators". Both pickers fill (8th Suffolk, Third Suffolk) and the matched address is shown.
Try 455 Main St, Worcester. It should match Worcester itself, not other towns in Worcester County.
Try 100 Warren St, Boston. You're asked to choose between Charlestown, Roxbury and Warren Ave; pick one and the pickers fill.
Try 1 Main St, Greenfield. The House seat (1st Franklin) is reported as possibly vacant.
Try Beacon St, Boston (asks for a street number) and 1 Main St, Portland ME (not found).
Start a testimony without legislators set: the same box appears on "Select Your Legislators".
Add ?legislatorAddressLookup=disabled and confirm the old text and link come back.

Checks run: yarn check-types, yarn check-formatting, yarn lint (no warnings in changed files), yarn test:website (47 suites, including the two new ones), yarn test (32 suites).

🤖 Generated with Claude Code

https://claude.ai/code/session_01D33UhQEt1gm2oVFCq3FdXf
address-lookup-choose_1
address-lookup-found_1

Adds an address box above the Representative and Senator pickers, on
Edit Profile and on the testimony flow's "Select Your Legislators" step.
The browser geocodes the address with MassGIS's statewide geocoder, finds
the House and Senate districts in MassGIS's 2021 district layers, and
fills both pickers from MAPLE's member search index. The address is not
sent to MAPLE's servers or saved. Behind the legislatorAddressLookup flag
(on in development, off in production).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01D33UhQEt1gm2oVFCq3FdXf
@vercel

vercel Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
maple-dev Ready Ready Preview Nov 24, 2026 4:35pm UTC

Request Review

@Mephistic

Copy link
Copy Markdown
Collaborator

This looks like it implements an older ticket - #1022 - just leaving that here for context

This branch was successfully deployed

1 active deployment
Preview – maple-dev — 093eeb29 Deployed Nov 24, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants