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

Method get_distance

bmtools/tools/map/baidu_map/baidu_api.py:117–137  ·  view source on GitHub ↗

该函数仅适用于中国境内地图(内陆),this function only suitable for locations in Mainland China 查询两地之间的距离 :param origin: 起点地址 :param destination: 终点地址 :return: 两地之间距离(米)

(self, origin: str, destination: str)

Source from the content-addressed store, hash-verified

115 return None
116
117 def get_distance(self, origin: str, destination: str) -> float:
118 """
119 该函数仅适用于中国境内地图(内陆),this function only suitable for locations in Mainland China
120 查询两地之间的距离
121 :param origin: 起点地址
122 :param destination: 终点地址
123 :return: 两地之间距离(米)
124 """
125 origin_location = self.get_location(origin)
126 destination_location = self.get_location(destination)
127 if origin_location and destination_location:
128 origin_lat, origin_lng = origin_location
129 destination_lat, destination_lng = destination_location
130 url = f'{self.base_url}/direction/v2/transit?origin={origin_lat},{origin_lng}&destination={destination_lat},{destination_lng}&output=json&ak={self.ak}'
131 url = self.generate_url_with_sn(url)
132 response = requests.get(url)
133 data = response.json()
134 if data['status'] == 0:
135 distance = data['result']['routes'][0]['distance']
136 return distance
137 return None
138
139def build_tool(config) -> Tool:
140 tool = Tool(

Callers 1

get_distanceFunction · 0.45

Calls 2

get_locationMethod · 0.95
generate_url_with_snMethod · 0.95

Tested by

no test coverage detected