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