Validate existing latitude/longitude values for a list of properties by re-geocoding each address with the Google Maps Geocoding API and comparing results.
- Reads a list of properties (each with an
id,address,latitude,longitude). - Geocodes each
addressvia Google Maps. - Compares the geocoded coordinates against the provided coordinates.
- Produces:
- A short summary (how many match vs. don’t match)
- A list of the properties that do not match, in the same column format as the input
Your input file should contain (at minimum) these columns:
id(unique identifier)address(full address string)latitude(decimal degrees)longitude(decimal degrees)
For the most accurate geocoding results, the address value should include:
- Street number (e.g.,
1600) - Street name (e.g.,
Amphitheatre Parkway) - City
- Province/State
- Postal/ZIP code (recommended)
Addresses missing key parts (like street number, city, or province/state) are more likely to geocode to the wrong place or return inconsistent results.
Example (CSV):
id,address,latitude,longitude
1,"1600 Amphitheatre Parkway, Mountain View, CA 94043, USA",37.4220,-122.0841
2,"11 Wall St, New York, NY 10005, USA",40.7074,-74.0113The script produces two things:
- A summary report (e.g. total rows checked, count matched, count mismatched)
- A “mismatches” file containing only the rows where the provided coordinates do not match the geocoded result.
The mismatches output keeps the same core columns as the input (id, address, latitude, longitude) and adds:
google_latitudegoogle_longitudedistance_meters(only populated when both coordinate pairs are valid)
You’ll need a Google Maps API key with access to the Geocoding API.
Set your API key as an environment variable (recommended) so you don’t commit secrets:
export GOOGLE_MAPS_API_KEY="your_api_key_here"If you’re using a local .env file, keep it out of git (this repo’s .gitignore already ignores .env).
This repo includes a template you can copy:
cp .env.example .envFrom the repo directory, make the script executable (one-time) and run it:
chmod +x geocode_check.py
./geocode_check.py --input properties.csv --tolerance-meters <METERS>If you prefer, you can also run it with Python:
python geocode_check.py --input properties.csv --tolerance-meters <METERS>Geocoded coordinates may not exactly match your stored coordinates (due to rounding, different data sources, or changes in geocoding over time). This tool treats a property as a match if the distance between the two coordinate pairs is within --tolerance-meters.
Write mismatched rows to a CSV file:
./geocode_check.py --input properties.csv --mismatches-output mismatches.csv --tolerance-meters <METERS>To avoid re-geocoding the same addresses across runs, you can enable a simple on-disk cache:
./geocode_check.py --input properties.csv --tolerance-meters <METERS> --cache-file .geocode_cache.jsonRows are handled like this:
- Missing/invalid
latitudeorlongitude: counted as a mismatch (written tomismatches.csv) with a clear stderr message. - Rows that cannot be geocoded by Google (missing address, geocode failure, or ambiguous result): skipped with a clear stderr message explaining why.
If you see errors like CERTIFICATE_VERIFY_FAILED when calling Google, your Python environment may be missing trusted root certificates.
- Recommended fix: install
certifiin your venv:
~filepath/property-geocode-checker/venv/bin/python -m pip install --upgrade certifi- If it still fails, try setting this for the current shell session:
export SSL_CERT_FILE="$(~filepath/property-geocode-checker/venv/bin/python -c 'import certifi; print(certifi.where())')"