Created
June 17, 2021 11:52
-
-
Save KaushikShresth07/403b0d3e7b84c984cadfee61f18b57b6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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