Lately I’ve been working on projects that require quick geocoding in the browser based on a user search. Here I want to share two specific geocoding services that have worked well for me, have been cost effective (free), and return seemingly solid results: Census and Mapbox. Both services allow for one to structure an HTTP query with an address and the response comes in JSON format with the appropriate latitude and longitude information.
The Census Geocoder
- One Line Address: allows you to send a single string into the query
- Address parameters: build the parameters for each part of the address
We’ll focus on the One Line Address for simplicity’s sake. The HTTP endpoint is as follows:
The necessary parameters are as follows:
address– the address string you are looking for
benchmark– A numerical ID or name that references what version of the locator should be searched. Here’s a list of benchmarks.
format– format of the response. Typically used with
An example call for the location of The Old Fashioned bar in Madison, WI with the address 23 North Pinkney St. Madison WI:
Mapbox offers a great geocoding service that is very much like the Census, allowing for HTTP requests. They require an API key but beyond that you can make many calls to their API without going over the limit. One thing that draws me to the Mapbox version is the ability to make multiple queries for different addresses in the same request using their batch geocoding service (allowing up to 50 per request). Here’s an example searching for three different zip codes:
The response is an array of objects with the geometry information for the respective features.