Analyzing cities, with Lambda Labs

I’ve moved quite a few times in my life.

Allison Usher
4 min readMar 4, 2021

Moving is a terrifying thing, and often when I moved, all I knew about where I was moving to was that it was affordable and available. Most of the time, this worked out well, but it very well could have not. Problems like this are the problem we set forth to resolve in our City-Spire application. We could aggregate data such as walkability, cost of living, crime, and education with a simple search and show users the places that fit them the most. But where would we get this data?

A view from above

In our City-Spire app, we needed to view a map of the city we were looking at and search for a city at will. As per the guidelines of the project, we utilized Mapbox for both these tasks. Using Mapbox’s mapboxgl npm package, I successfully displayed a map full-screen on our landing page. And with their geocoding software, a search bar was added as well, with autocomplete functionality.

A beautiful view of the Seattle area

But there was an issue, while we could search for a city and have it displayed, our Data Science back end team needed more than just the City and State that users were entering into the search bar, and what if the user had scrolled to a new area on the map? And so I got to work.

Browsing Mapbox’s API, I found that while they didn’t have reverse geocoding functionality built into their mapboxgl package, they did have an API that allowed the functionality. I quickly wrote a function that would send the latitude and longitude at the map’s center to their reverse geocoding API whenever the map moved.

Mapbox’s SDK offers a very clean way of crafting your API call

And while this worked, I quickly realized that if we searched every time the map moved, we would soon run into trouble for too many calls. So what was there to do? The solution, I realized, was to add a delay to the search, creating a queue in state, and rather than make the call to the API on the move; we would enqueue the current latitude and longitude to this array and set a timeout that would check to see if the queue only had one item in it. If not, it would dequeue and exit safely until delayed callback fired for the last set of coordinates in the queue.

Once we were here, we knew the user had stopped moving the map and could safely make our API call without fear of running afoul of Mapbox’s servers.

Waiting on the world to change

With our map in place and ready to send information that our Data Science team, we were finally set up to display the analyzed data. Unfortunately, due to some technical bugs on the DS server, we were ultimately unable to integrate this information into our application by the deadline, and our application is mostly just a way to view a map of the united states and know the city, state, and zip code. We performed a few last-minute adjustments, integrating our reverse geocoding into the back end so that our keys remained hidden on our front end page and editing the styles of the map so that the colors would match our desired color palette.

But with those technical issues finally resolved on the back end, this project would very quickly be able to add in the features we had planned. Who knows even, it would most likely be able to grow in infinite possible ways. Given enough development, I could see this application adding user pins, area reviews by fellow users, and even visualization of our DS team’s data using Mapbox’s tiles. Though I am saddened we couldn’t finalize all the features we wanted to add, I still feel like our team gave our all to this project, and working with my fellow teammates was a wonderful experience, as previous build week projects I had worked on, I had always been the sole member of my Unit in the project. If anything, this project has helped me realize that sometimes problems happen that just can’t be brute-forced, and that’s okay, even if it is a bit disappointing. Coming away from this project disappointed will help me prepare for real-life scenarios where despite everyone giving their all, a project just doesn’t come to fruition. All that matters is that you work with passion and give it your all because, in disappointment, there is learning to be had.

--

--