Skip to content

Instantly share code, notes, and snippets.

@KaushikShresth07
Created June 12, 2021 13:27
Show Gist options
  • Select an option

  • Save KaushikShresth07/593921c42e68373b3f70d6512bc5a397 to your computer and use it in GitHub Desktop.

Select an option

Save KaushikShresth07/593921c42e68373b3f70d6512bc5a397 to your computer and use it in GitHub Desktop.
from geopy.distance import great_circle # pip install geopy
from geopy.geocoders import Nominatim # pip install geopy
import webbrowser # pip install webbrowser
import geocoder # pip install geocoder
import requests
def GoogleMaps(Place):
Url_Place = "https://www.google.com/maps/place/" + str(Place)
geolocator = Nominatim(user_agent="myGeocoder")
location = geolocator.geocode(Place , addressdetails= True)
target_latlon = location.latitude , location.longitude
webbrowser.open(url=Url_Place)
location = location.raw['address']
target = {'city' : location.get('city',''),
'state' : location.get('state',''),
'country' : location.get('country','')}
current_loca = geocoder.ip('me')
current_latlon = current_loca.latlng
distance = str(great_circle(current_latlon,target_latlon))
distance = str(distance.split(' ',1)[0])
distance = round(float(distance),2)
return f'''
{target} .
{Place} Is {distance} Kilometre Away From Your Place .
'''
def My_Location():
op = "https://www.google.com/maps/place/Delhi/@28.6472799,76.8130619,83757m/data=!3m2!1e3!4b1!4m5!3m4!1s0x390cfd5b347eb62d:0x37205b715389640!8m2!3d28.7040592!4d77.1024902"
webbrowser.open(op)
ip_add = requests.get('https://api.ipify.org').text
url = 'https://get.geojs.io/v1/ip/geo/' + ip_add + '.json'
geo_q = requests.get(url)
geo_d = geo_q.json()
state = geo_d['city']
country = geo_d['country']
return f"Sir , You Are Now In {state , country} ."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment