Skip to content

Commit 2646b7a

Browse files
committed
Script to perform geocoding
1 parent 1374c05 commit 2646b7a

3 files changed

Lines changed: 39 additions & 0 deletions

File tree

projects/Geocoding/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
## Geocoding Script
2+
3+
### This script takes an address and return its latitude and longitude.This process is called geocoding
4+
5+
#### I have used the locationiq website's geocoding api inorder to solve this problem.
6+
7+
#### To be able to use this script you have to create a *free account* at https://locationiq.com/ and obtain your *private token*.
8+
9+
#### Remember, *don'tshare* your private token with anyone.

projects/Geocoding/geocoding.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import requests
2+
3+
# Base Url for geocoding
4+
url = "https://us1.locationiq.com/v1/search.php"
5+
6+
address = input("Input the address: ")
7+
8+
#Your unique private_token should replace value of the private_token variable.
9+
#To know how to obtain a unique private_token please refer the README file for this script.
10+
private_token = "6c0a7b6f14b7cb"
11+
12+
data = {
13+
'key': private_token,
14+
'q': address,
15+
'format': 'json'
16+
}
17+
18+
response = requests.get(url, params=data)
19+
20+
latitude = response.json()[0]['lat']
21+
longitude = response.json()[0]['lon']
22+
23+
print(f"The latitude of the given address is: {latitude}")
24+
print(f"The longitude of the given address is: {longitude}")
25+
print("Thanks for using this script")
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
certifi==2020.6.20
2+
chardet==3.0.4
3+
idna==2.10
4+
requests==2.24.0
5+
urllib3==1.25.10

0 commit comments

Comments
 (0)