Commit e74cccde authored by 李小芳's avatar 李小芳

Merge branch 'hisp' into 'master'

add

See merge request !78
parents 537d95fd 622a216a
...@@ -58,26 +58,26 @@ def point_distance(lon1, lat1, lon2, lat2): ...@@ -58,26 +58,26 @@ def point_distance(lon1, lat1, lon2, lat2):
# haversine公式 # haversine公式
dlon = lon2 - lon1 dlon = lon2 - lon1
dlat = lat2 - lat1 dlat = lat2 - lat1
a = sin(dlat / 2)**2 + cos(lat1) * cos(lat2) * sin(dlon / 2)**2 a = sin(dlat / 2) ** 2 + cos(lat1) * cos(lat2) * sin(dlon / 2) ** 2
c = 2 * asin(sqrt(a)) c = 2 * asin(sqrt(a))
r = 6371 # 地球平均半径,单位为km r = 6371 # 地球平均半径,单位为km
return c * r * 1000 return c * r * 1000
class HostpitalPosInfo(object): class HostpitalPosInfo(object):
hospital_pos_dict = dict() hospital_pos_dict = dict()
@classmethod @classmethod
def get_hostpital_info(cls): def get_hostpital_info(cls):
try: try:
if len(cls.hospital_pos_dict) == 0: if len(cls.hospital_pos_dict) == 0:
query_results = doctor.Hospital.objects.filter(is_online=True) query_results = doctor.Hospital.objects.filter()
#query_results = django.db.models.QuerySet(model=doctor.Hospital, query=query) # query_results = django.db.models.QuerySet(model=doctor.Hospital, query=query)
for item in query_results: for item in query_results:
name = item.name name = item.name
lng = float(item.baidu_loc_lng) lng = float(item.baidu_loc_lng)
lat = float(item.baidu_loc_lat) lat = float(item.baidu_loc_lat)
cls.hospital_pos_dict[name] = [lng,lat] cls.hospital_pos_dict[name] = [lng, lat]
return cls.hospital_pos_dict return cls.hospital_pos_dict
except: except:
...@@ -85,4 +85,4 @@ class HostpitalPosInfo(object): ...@@ -85,4 +85,4 @@ class HostpitalPosInfo(object):
return cls.hospital_pos_dict return cls.hospital_pos_dict
g_hospital_pos_dict = HostpitalPosInfo.get_hostpital_info() g_hospital_pos_dict = HostpitalPosInfo.get_hostpital_info()
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment