Get Coordinates of a Location via Mapbox’s Geocoding API

Richard Gao
Aug 20, 2021

--

Got Python? Got 5 minutes? Want to know the exact coordinates of a location you have in mind for free, such as the image below? Then let’s get into it.

Download the relevant libraries:

Query the API:

This defines a function that takes in a query and your Mapbox API key in order to query Mapbox’s geocoding API: https://docs.mapbox.com/api/search/geocoding/

Don’t have an API key? Get one here: https://docs.mapbox.com/help/getting-started/access-tokens/

Explanation

In this code snippet we are using the function, queryMapBox, to look for MIT Cambridge. From the output of the queryMapBox function, we load the data into a readable json format using the json.loads() function. Then, normalize that json data into a DataFrame using the json_normalize() function. The results:

Done! Happy Coding.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Richard Gao
Richard Gao

Written by Richard Gao

Computer Science and Data Enthusiast | Linkedin: https://www.linkedin.com/in/richard-gao-csecon/ | Shovelling data into the AI engine

No responses yet

Write a response