# import all the required libraries import geopy from geopy import Nominatim from geopy import distance # function to carry out the specific geographic operations def location(): """ :return: using the Nominatim API and GeoPy package to give following solutions """ geolocator = Nominatim(user_agent="geoapiExercises")
# To search the Street address, Name from a given location information add1 = "Koramangala, Bengaluru" print("Location address:", add1) location = geolocator.geocode(add1) print("Street address, street name is: ", location.address)
# To search the Country Name from given state name state1 = "Uttarakhand" print("State Name:", state1) location = geolocator.geocode(state1) print("State Name/Country Name is: ", location.address)
# To search the details of a given Zip Code zipcode1 = "248001" print("\nZipcode:", zipcode1) location = geolocator.geocode(zipcode1) print("Details of the said pincode are:", location.address)
# To search the Latitude and Longitude of a given location lat_long = "Whitefield, Bengaluru" print("Location address:", lat_long) location = geolocator.geocode(lat_long) print("Latitude and Longitude of the said address is:", (location.latitude, location.longitude))
# To search the location address of a specified Latitude and Longitude la_ld = "47.470706, -99.704723" print("Latitude and Longitude:", la_ld) location = geolocator.geocode(la_ld) print("Location address of the said Latitude and Longitude is:", location)
# To get the City, State and Country name of a specified Latitude and Longitude coordinates = "47.470706, -99.704723" location1 = geolocator.reverse(coordinates, exactly_one=True) address1 = location1.raw['address'] city = address1.get('city', '') state = address1.get('state', '') country = address1.get('country', '') print("City:", city, "State:", state, "Country:", country)
# To calculate the distance between London and New York city london = "51.5074° N, 0.1278° W" new_york = "40.7128° N, 74.0060° W" print("Distance between London and New York city (in km) is:") print(distance.distance(london, new_york).km, " kms") # To convert an address and return its geographic coordinates add = "1600 Amphitheatre Parkway, Mountain View, CA" location = geolocator.geocode(add) print("Latitude = {}, Longitude = {}".format(location.latitude, location.longitude)) # function call if __name__ == "__main__" location() |
Comments
Post a Comment