MCPcopy Create free account
hub / github.com/OpenBMB/BMTools / get_route

Method get_route

bmtools/tools/map/baidu_map/test_baidu.py:83–108  ·  view source on GitHub ↗

该函数仅适用于中国境内地图(内陆),this function only suitable for locations in Mainland China 查询两地之间的路线 :param origin: 起点地址 :param destination: 终点地址 :return: 路线描述列表,若无法获取则返回None

(self, origin: str, destination: str)

Source from the content-addressed store, hash-verified

81 else:
82 return []
83 def get_route(self, origin: str, destination: str) -> Optional[List[str]]:
84 """
85 该函数仅适用于中国境内地图(内陆),this function only suitable for locations in Mainland China
86 查询两地之间的路线
87 :param origin: 起点地址
88 :param destination: 终点地址
89 :return: 路线描述列表,若无法获取则返回None
90 """
91 origin_location = self.get_location(origin)
92 destination_location = self.get_location(destination)
93 if origin_location and destination_location:
94 origin_lat, origin_lng = origin_location
95 destination_lat, destination_lng = destination_location
96 url = f'{self.base_url}/direction/v2/transit?origin={origin_lat},{origin_lng}&destination={destination_lat},{destination_lng}&output=json&ak={self.ak}'
97 url = self.generate_url_with_sn(url)
98 response = requests.get(url)
99 data = response.json()
100 if data['status'] == 0:
101 routes = data['result']['routes']
102 instructions = []
103 for route in routes:
104 for step in route['steps']:
105 for item in step:
106 instructions.append(item['instructions'])
107 return instructions
108 return None
109
110 def get_distance(self, origin: str, destination: str) -> float:
111 """

Callers 1

test_baidu.pyFile · 0.45

Calls 2

get_locationMethod · 0.95
generate_url_with_snMethod · 0.95

Tested by

no test coverage detected