Template request | Bug report | Generate Data Product
Tags: #python #geocoding #city #coordinates #location #api
Author: Florent Ravenel
Description: This notebook will show how to get coordinates from an address using Python and display it on a map.
References:
try:
import geocoder
except:
!pip install geocoder --user
import geocoder
import pandas as pd
import plotly.express as px
address
: address to get coordinates from
address = "Sayyaji Rao Rd, Agrahara, Chamrajpura, Mysuru, Karnataka 570001"
Using the geocoder
library, we can get the coordinates from a city name.
g = geocoder.arcgis(address)
lat, lng = g.latlng
df = pd.DataFrame([{"name": address, "latitude": lat, "longitude": lng, "size": 1}])
print(f"Coordinates of {address}: {lat}, {lng}")
fig = px.scatter_mapbox(
df,
lat='latitude',
lon='longitude',
size='size',
text='name',
zoom=10,
mapbox_style='open-street-map'
)
fig.update_layout(
width=1200,
height=800,
)
config = {"displayModeBar": False}
fig.show(config=config)