Links

Get coordinates from address

Tags: #python #snippet #naas #geocoder
Author: Suhas B​
Last update: 2023-04-12 (Created: 2023-03-24)
Description: This notebook get coordinates from a given address.
References:

Input

Import libraries

try:
import geocoder
except:
!pip install geocoder --user
import geocoder

Setup Variables

# sample address to geo code
address = "Sayyaji Rao Rd, Agrahara, Chamrajpura, Mysuru, Karnataka 570001"

Model

Get data from geocoder

geo = geocoder.arcgis(address)

Output

Display latitude and longitude from address

latitude_and_longitude = geo.latlng
print(f"Latitude and Longitude of given address '{address}':\n{latitude_and_longitude}\n")
​
# If we want to retrieve the location from a set of coordinates
# perform a reverse query.
​
location_from_coordinates = geocoder.arcgis(latitude_and_longitude, method="reverse")
print(f"Location from coordinates:\n{location_from_coordinates[0]}")