-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlocation.py
More file actions
28 lines (21 loc) · 757 Bytes
/
Copy pathlocation.py
File metadata and controls
28 lines (21 loc) · 757 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import requests
import math
def get_location():
res = requests.get('https://ipinfo.io/')
data = res.json()
lat_testing=data['loc'].split(',')[0]
lon_testing=data['loc'].split(',')[1]
lat_testing=math.radians(float(lat_testing))
lon_testing=math.radians(float(lon_testing))
lat_office=math.radians(28.66010)
lon_office=math.radians(77.12705)
dlon=abs(lon_office-lon_testing)
dlat=abs(lat_office-lat_testing)
R=6373.0
a = math.sin(dlat / 2)**2 + math.cos(lat_office) * math.cos(lat_testing) * math.sin(dlon / 2)**2
c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a))
distance = R * c
if(distance<0.5):
return "Inside Office premises"
else:
return "Outside Office premises"