该函数仅适用于中国境内地图(内陆),this function only suitable for locations in Mainland China 根据地址获取地点经纬度, return the coordinates :param address: 地址 :return: 地点经纬度 (纬度, 经度),若无法获取则返回None; return (latitute, longitute)
(self, address: str)
| 29 | return url_with_sn |
| 30 | |
| 31 | def get_location(self, address: str) -> Optional[Tuple[float, float]]: |
| 32 | """ |
| 33 | 该函数仅适用于中国境内地图(内陆),this function only suitable for locations in Mainland China |
| 34 | 根据地址获取地点经纬度, return the coordinates |
| 35 | :param address: 地址 |
| 36 | :return: 地点经纬度 (纬度, 经度),若无法获取则返回None; return (latitute, longitute) |
| 37 | """ |
| 38 | url = f'{self.base_url}/geocoding/v3/?address={address}&output=json&ak={self.ak}&callback=showLocation' |
| 39 | url = self.generate_url_with_sn(url) |
| 40 | response = requests.get(url) |
| 41 | json_text = response.text[len('showLocation&&showLocation('):-1] |
| 42 | data = json.loads(json_text) |
| 43 | if data['status'] == 0: |
| 44 | result = data['result'] |
| 45 | location = result['location'] |
| 46 | return location['lat'], location['lng'] |
| 47 | else: |
| 48 | return None |
| 49 | |
| 50 | def get_address_by_coordinates(self, lat: float, lng: float) -> Optional[str]: |
| 51 | """ |
no test coverage detected