一、百度与高德坐标系互换
百度坐标系:bd09
高德坐标系: gcj02
import math# 坐标系转换:百度转高德,高德转百度
class CoordinateSystem:@staticmethoddef bd09_to_gcj02(bd_lon, bd_lat):'''百度坐标系:bd09 转成高德坐标系 gcj02Args:bd_lon: 百度坐标系纬度bd_lat: 百度坐标系经度Return:(高德坐标系纬度,高德坐标系经度)'''bd_lon = float(bd_lon)bd_lat = float(bd_lat)x = bd_lon - 0.0065y = bd_lat - 0.006z = math.sqrt(x * x + y * y) - 0.00002 * math.sin(y * math.pi)theta = math.atan2(y, x) - 0.000003 * math.cos(x * math.pi)gcj_lon = z * math.cos(theta)gcj_lat = z * math.sin(theta)return gcj_lon, gcj_lat@staticmethoddef gcj02_to_bd09(lon, lat):'''高德坐标系:gcj02 转成高德坐标系 bd09Args:lon: 高德坐标系纬度lat: 高德坐标系经度Return:(高德坐标系纬度,高德坐标系经度)'''lon = float(lon)lat = float(lat)z = math.sqrt(lon * lon + lat * lat) + 0.00002 * math.sin(lat * math.pi)theta = math.atan2(lat, lon) + 0.000003 * math.cos(lon * math.pi)bd_lon = z * math.cos(theta) + 0.0065bd_lat = z * math.sin(theta) + 0.006return bd_lon, bd_latif __name__ == '__main__':lon = 23.0534260666666lat = 113.40712125gd_lob,gd_lat = CoordinateSystem.bd09_to_gcj02(bd_lon=lon,bd_lat=lat)