forked from SzTk/Get-Mid-Point
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest2.py
More file actions
29 lines (24 loc) · 1.09 KB
/
test2.py
File metadata and controls
29 lines (24 loc) · 1.09 KB
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
#coding: UTF-8
#Geographic midpoint
#http://www.geomidpoint.com/meet/
#http://www.geomidpoint.com/calculation.html
from math import (pi, sin, cos, atan2, sqrt)
from get_mid_point import (pygmapslib, directions, geocoding, placesearch)
def get_middle_point(coordinates):
x = 0
y = 0
z = 0
for point in coordinates:
x = x + cos(point['lat'] * pi / 180) * cos(point['lng'] * pi /180)
y = y + cos(point['lat'] * pi / 180) * sin(point['lng'] * pi /180)
z = z + sin(point['lat'] * pi / 180)
x = x / len(coordinates)
y = y / len(coordinates)
z = z / len(coordinates)
return {'lng' : atan2(y,x) * 180 / pi, 'lat' : atan2(z, sqrt(x*x + y*y)) * 180 /pi}
point1 = geocoding.request('Tokyo station')
point2 = geocoding.request('Ikebukuro station')
point3 = geocoding.request('Shibuya station')
middle_cord = get_middle_point([point1.data[0]['geometry']['location'], point2.data[0]['geometry']['location'], point3.data[0]['geometry']['location']])
stations = placesearch.get_nearest_station(middle_cord, key='XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
print stations