-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdistance.py
More file actions
executable file
·25 lines (22 loc) · 899 Bytes
/
Copy pathdistance.py
File metadata and controls
executable file
·25 lines (22 loc) · 899 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
#!/usr/bin/python
#-*-encoding:utf-8 -*-
#方法来自于Google Map
#计算地球上两点之间的距离,坐标用经纬度表示。
#1公里范围误差1米左右
import math
import sys
def distance (latA,lonA,latB,lonB):
earth_radius = 6378137.0
radlatA = math.radians(latA)
radlonA = math.radians(lonA)
radlatB = math.radians(latB)
radlonB = math.radians(lonB)
diffLat = radlatA - radlatB
diffLon = radlonA - radlonB
distan = 2 * math.asin(math.sqrt(math.pow(math.sin(diffLat/2),2) + math.cos(radlatA)*math.cos(radlatB)*math.pow(math.sin(diffLon/2),2)))
distan =round(distan * earth_radius ,2)
return distan
# Two Examples to call the function.
#print distance(float(sys.argv[1]) , float(sys.argv[2]),float(sys.argv[3]),float(sys.argv[4]))
print distance(30.51372 , 114.42658,30.50929,114.42150)
print distance(30.50929,114.42150,30.5766,111.8457)