Python 3 Reverse Geocoding Script to Convert Addresses to Latitude and Longitude Using Locationiq Library Full Project For Beginners

Python 3 Reverse Geocoding Script to Convert Addresses to Latitude and Longitude Using Locationiq Library Full Project For Beginners

 

Welcome folks today in this post we will be doing reverse geocoding and converting addresses to latitude and longitude using Locationiq library in python. All the full source code of the application is shown below.

 

 

Get Started

 

 

In order to get started you need to get the locationiq private access token  by going to their official website

See also  Python (PyAutoGUI) Tkinter GUI Script to Make a Screen Recorder and Screenshot App Using PyWinAuto Library Full Tutorial For Beginners

 

 

 

Here you need to copy your private access_token from this dashboard and store it we will use it in the script

 

And now make an app.py script file and copy paste the following code

 

app.py

 

import requests

# Base Url for geocoding
url = "https://us1.locationiq.com/v1/search.php"

address = input("Input the address: ")

#Your unique private_token should replace value of the private_token variable.
#To know how to obtain a unique private_token please refer the README file for this script.
private_token = "###privateaccesstoken####"

data = {
    'key': private_token,
    'q': address,
    'format': 'json'
}

response = requests.get(url, params=data)

latitude = response.json()[0]['lat']
longitude = response.json()[0]['lon']

print(f"The latitude of the given address is: {latitude}")
print(f"The longitude of the given address is: {longitude}")
print("Thanks for using this script")

 

See also  Python 3 Script to Download PDF Files From URL Using BeautifulSoup4 and Requests Library Full Tutorial For Beginners

 

And now if you execute the python script by typing the below command

 

python app.py

 

 

 

And now you can see that i have provided the address and it has converted to latitude and longitude

Leave a Reply