How I created a ‘Parks Finder’ web app
Do you know where the closest National Park is?
The next question was how to match up a user’s location with the closest sites.
Using a small amount of initial data, I wrote functions that turned the user’s address into latitude and longitude, using Google’s Geocoding API. I then compared those coordinates to the sample of the national sites, returning the closest location in each category, and the distance.
Although I initially started using the Google Maps Distance Matrix API to calculate distances between points, it became clear that wouldn’t work once I used all the data, since the API accepts a maximum of 25 destinations per request. There are more than 200 National Historic Sites, National Parks and National Marine Conservation Areas combined.
However, the only necessary API function was geocoding the address, since I could use a math formula to calculate the distances. I decided to limit the API usage to geolocation, which has less usage restrictions per request.
The math I used instead, called the haversine formula, calculates the distance between points “as the crow flies,” meaning the distance was exact, rather than driving or another transportation route. (Shout out to the helpful community over at Stack Overflow for giving me the idea and code.)
The web app was eventually used by more than 1,000 people in January at consultation events. We heard from several users that, prior to using our app, they hadn’t known what the closest sites were.