Skip to content

Commit

Permalink
Added Distance Calculator App (HarshCasper#795)
Browse files Browse the repository at this point in the history
* 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
Aayush-hub authored Mar 27, 2021
1 parent 57c0f7e commit 9ab4862
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
23 changes: 23 additions & 0 deletions Python/Distance_Calculator_App/README.md
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)
38 changes: 38 additions & 0 deletions Python/Distance_Calculator_App/main.py
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 added Python/Distance_Calculator_App/requirements.txt
Binary file not shown.

0 comments on commit 9ab4862

Please sign in to comment.