Ranking capitals by the number of Starbucks using Python and Google Maps API

Artem Rys
python4you
Published in
2 min readJul 22, 2019

--

Starbucks logo
Photo by Khadeeja Yasser on Unsplash

Recently being in Budapest (great city by the way) I saw lots of Starbucks coffee shops and decided to write a small script that will rank capitals by the number of Starbucks there.

I am not pretending to get the most accurate results, it is just an example. So, please don’t use it make some serious business decisions :)

We will use Google Places API and a local copy of a bit reworked list of capitals’ coordinates from here.

The full code is available here.

First of all, let me say that Google Places API has a serious limitation of returning maximum 60 results for one search. That’s why we need to be a bit tricky. We will request it several times with different coordinates and then count a number of unique places that we got.

Probably not the best solution but it at least simple and returns more than 60 places. If you need more precise results there are lots of Google Places API wrappers around the web.

To run it by yourself you need to get a key. Don’t be afraid about money, I spent 0$ while I was testing my code.

--

--

Artem Rys
python4you

Principal Software Engineer @ Splunk. Writing about Python, GitHub and Splunk.