forked from HarshCasper/Rotten-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Distance Calculator App (HarshCasper#795)
* Added Distance Calculator App * Added Distance-Calculating-App * Updated Readme.md * Added Distance Calculator App * Added Distance calculator app * Added Distance Calculator App * Updated image * Added Distance Calculator app
- Loading branch information
1 parent
57c0f7e
commit 9ab4862
Showing
3 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Distance Calculating App | ||
Calculating distance between two locations is a basic requirement if you are working with raw location data. This app calculates distance between two geo-locations. You can get distance in kilometers between two locations just by entering names of the locations. | ||
|
||
## Quick Start: | ||
|
||
- Change Directory | ||
|
||
``` cd .\Rotten-Scripts\Python\Distance_Calculator_App\ ``` | ||
|
||
- Install requirememnts | ||
|
||
`pip install -r requirements.txt` | ||
|
||
- Run python file | ||
|
||
`python main.py --firstlocation <enter first location here> --secondlocation <enter second location here>` | ||
|
||
## Screenshot | ||
|
||
![Screenshot](https://i.imgur.com/r7ImdqE.jpg) | ||
|
||
## Author | ||
[Aayush Garg](https://github.com/Aayush-hub) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import argparse | ||
from geopy.geocoders import Nominatim | ||
from geopy import distance | ||
|
||
def location(): | ||
""" A program to calculate distance between two geo-locations | ||
Parameters: | ||
firstlocation (str): The starting location of user | ||
secondlocation (str): The final location of user | ||
""" | ||
geolocator = Nominatim(user_agent="geoapiExercises") | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument('--firstlocation', type=str, required=True) | ||
parser.add_argument('--secondlocation', type=str, required=True) | ||
args = parser.parse_args() | ||
|
||
# calculating longitude and latitude of entered locations """ | ||
try: | ||
first_location = geolocator.geocode(args.firstlocation) | ||
second_location = geolocator.geocode(args.secondlocation) | ||
Loc1_lat,Loc1_lon = (first_location.latitude),(first_location.longitude) | ||
Loc2_lat,Loc2_lon = (second_location.latitude),(second_location.longitude) | ||
|
||
location1=(Loc1_lat,Loc1_lon) | ||
location2=(Loc2_lat,Loc2_lon) | ||
|
||
# calculating and printing distance between locations in Kilometers and Miles.""" | ||
|
||
res = ((distance.distance(location1, location2).km)) | ||
distance_miles = float(res)*0.621371 | ||
print (f"The total distance is: {res} Km , {distance_miles} Miles") | ||
except: | ||
print("Invalid Location") | ||
|
||
if __name__ == "__main__": | ||
location() | ||
|
Binary file not shown.