奥维地图怎么转换成GCJ—02坐标
时间: 2023-05-18 09:06:27 浏览: 136
您可以使用以下代码将WGS84坐标转换为GCJ-02坐标:
```python
import math
def transform(lat, lng):
a = 6378245.0
ee = 0.00669342162296594323
pi = math.pi
def out_of_china(lat, lng):
if lng < 72.004 or lng > 137.8347:
return True
if lat < 0.8293 or lat > 55.8271:
return True
return False
def transform_lat(x, y):
ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * math.sqrt(abs(x))
ret += (20.0 * math.sin(6.0 * x * pi) + 20.0 * math.sin(2.0 * x * pi)) * 2.0 / 3.0
ret += (20.0 * math.sin(y * pi) + 40.0 * math.sin(y / 3.0 * pi)) * 2.0 / 3.0
ret += (160.0 * math.sin(y / 12.0 * pi) + 320 * math.sin(y * pi / 30.0)) * 2.0 / 3.0
return ret
def transform_lng(x, y):
ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * math.sqrt(abs(x))
ret += (20.0 * math.sin(6.0 * x * pi) + 20.0 * math.sin(2.0 * x * pi)) * 2.0 / 3.0
ret += (20.0 * math.sin(x * pi) + 40.0 * math.sin(x / 3.0 * pi)) * 2.0 / 3.0
ret += (150.0 * math.sin(x / 12.0 * pi) + 300.0 * math.sin(x / 30.0 * pi)) * 2.0 / 3.0
return ret
if out_of_china(lat, lng):
return lat, lng
d_lat = transform_lat(lng - 105.0, lat - 35.0)
d_lng = transform_lng(lng - 105.0, lat - 35.0)
rad_lat = lat / 180.0 * pi
magic = math.sin(rad_lat)
magic = 1 - ee * magic * magic
sqrt_magic = math.sqrt(magic)
d_lat = (d_lat * 180.0) / ((a * (1 - ee)) / (magic * sqrt_magic) * pi)
d_lng = (d_lng * 180.0) / (a / sqrt_magic * math.cos(rad_lat) * pi)
mg_lat = lat + d_lat
mg_lng = lng + d_lng
return mg_lat, mg_lng
```
然后,您可以使用以下代码将奥维地图的WGS84坐标转换为GCJ-02坐标:
```python
import requests
def convert_to_gcj02(lat, lng):
url = 'http://api.map.baidu.com/geoconv/v1/?coords={},{}&from=1&to=5&ak=您的AK'.format(lng, lat)
response = requests.get(url)
result = response.json()
if result['status'] == 0:
return result['result'][0]['y'], result['result'][0]['x']
else:
return None
```
请注意,您需要将“您的AK”替换为您的百度地图API密钥。
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)