DEV Community

vejendla
vejendla

Posted on

Geocoding addresses

I want to teach myself Leaflet.js, so I’m working on a project to rebuild this map as a Leaflet.js app. If you’re curious why I picked a website cataloguing old synagogues in Detroit as a project, read the readme on my GitHub to learn more.

So far, I’ve scraped the names and addresses of each former synagogue from the website, and have a .csv of them all that looks like this:

Image description

Some of the locations are listed as addresses (2625 Tyler), while some are listed as cross streets (Holbrook at Brush). A few are listed as general locations like “Curtis just west of Livernois”.

The next step in my project is to convert these addresses to coordinates.

Which service?

To do so, I need to geocode these locations. Geo-coding is the process of transforming a description of a location (like 2625 Tyler or Holbrook at Brush) to a set of coordinates referring to a specific place on the Earth.

There are several geo-coding services out there. While researching geocoding services, I found this StackExchange thread which lists a few options for geocoding. There’s also this article for Python which lists Google Maps. Here are some of the options I found:

First, I thought of using Nominatim (an Open Street Maps API), since it’s free. However, Open Street Maps (not the API) doesn’t recognize “Holbrook at Brush, Detroit, MI” as an address. I’m assuming that the API wouldn’t recognize it either, which is a problem.

Next, I thought about using Google Maps, which does recognize the address. However, their API requires me to get a key, which is a lot of work and may require me to set up a billing account. There’s one more place I can look…

Census to the rescue

The Census Bureau offers a free tool to geocode a .csv of addresses or locations in bulk. It works best for fully formed addresses (i.e., 400 Main St, Anywhere, NY). I can try uploading my .csv, and then filling in the missing addresses manually. Let’s give that a try:

Image description

It worked! Only 14 of the addresses didn’t have matches, which should be easy to fill in. Next, I copied the coordinates column back into my original spreadsheet. I ran into a roadblock here because it turns out that Numbers (on Mac) doesn’t actually have a SPLIT function. That seems like a tomorrow problem (it’s 9pm as of writing this), so I’ll move forward on filling in the missing values.

Using Google Maps, I found the first missing value, and right-clicked on the map to get the coordinates. It turns out that the Census and Google Maps return their coordinates in a different order. This also sounds like a tomorrow problem, so I’ll just copy them as is. 10 minutes later – I have a spreadsheet full of coordinates.

Image description

Next steps

Next, I need to:

  • reverse the order of the coordinates I copied from Google Maps
  • split the coordinates into their own columns
  • refer to this GitHub repo to read the .csv into my Leaflet.js map
  • figure out how to add both the name and the address of the each lost synagogue as part of the title card

Top comments (0)