资源简介
学习python加载百度、高德地图过程中,通过百度提供的纠偏接口速度缓慢,制作轨迹回放时速度缓慢,百度过很多资源,只有C#版本的纠偏类,随改为python3类,以供使用,已测试百度地图效果标点重合!
代码片段和文件信息
import math
x_PI = 3.14159265358979324 * 3000.0 / 180.0
PI = 3.1415926535897932384626
a = 6378245.0
ee = 0.00669342162296594323
class GpsConvert(object):
# * BD-09:百度坐标系(百度地图)
# * GCJ-02:火星坐标系(谷歌中国地图、高德地图)
# * WGS84:地球坐标系(国际通用坐标系,谷歌地图)
def __init__(self):
pass
#百度坐标系转火星坐标系
def bd09togcj02(selfbd_lon bd_lat):
x = bd_lon - 0.0065
y = bd_lat - 0.006
z = math.sqrt(x * x + y * y) - 0.00002 * math.sin(y * x_PI)
theta = math.atan2(y x) - 0.000003 * math.cos(x * x_PI)
gcj_lon = z * math.cos(theta)
gcj_lat = z * math.sin(theta)
gcj = [ gcj_lon gcj_lat ]//火星坐标系值
#火星坐标系转wgs84
wgs = self.gcj02towgs84(gcj[0] gcj[1])
return wgs
#火星坐标系转wgs84
def gcj02towgs84(selfgcj_lon gcj_lat):
if (self.out_of_china(gcj_lon gcj_lat)):
# //不在国内,不进行纠偏
back = [ gcj_lon gcj_lat ]
return back
else:
dlon = transformlon(gcj_lon - 105.0 gcj_lat - 35.0)
dlat = transformlat(gcj_lon - 105.0 gcj_lat - 35.0)
radlat = gcj_lat / 180.0 * PI
magic = math.sin(radlat)
magic = 1 - ee * magic * magic
sqrtmagic = math.sqrt(magic)
dlon = (dlon * 180.0) / (a / sqrtmagic * math.cos(radlat) * PI)
dlat = (dlat * 180.0) / ((a * (1 - ee)) / (magic * sqrtmagic) * PI)
mglon = gcj_lon + dlon
mglat = gcj_lat + dlat
wgs_lon = gcj_lon * 2 - mglon
wgs_lat = gcj_lat * 2 - mglat
wgs = [ wgs_lon wgs_lat ]//wgs84坐标系值
return wgs
# //火星坐标系转百度坐标系
def gcj02tobd09(selfgcj_lon gcj_lat):
z = math.sqrt(gcj_lon * gcj_lon + gcj_lat * gcj_lat) + 0.00002 * math.sin(gcj_lat * x_PI)
theta = math.atan2(gcj_lat gcj_lon) + 0.000003 * math.cos(gcj_lon * x_PI)
bd_lon = z * math.cos(theta) + 0.0065
bd_lat = z * math.sin(theta) + 0.006
bd = [ bd_lon bd_lat ]
return bd
# //wgs84转火星坐标系
def wgs84togcj02(selfwgs_lon wgs_lat):
if (self.out_of_china(wgs_lon wgs_lat)):
#//不在国内
back = [ wgs_lon wgs_lat ]
return back
else:
dwgs_lon = self.transformlon(wgs_lon - 105.0 wgs_lat - 35.0)
dwgs_lat = self.transformlat(wgs_lon - 105.0 wgs_lat - 35.0)
radwgs_lat = wgs_lat / 180.0 * PI
magic = math.sin(radwgs_lat)
magic = 1 - ee * magic * magic
sqrtmagic = math.sqrt(magic)
dwgs_lon = (dwgs_lon * 180.0) / (a / sqrtmagic * math.cos(radwgs_lat) * PI)
dwgs_lat = (dwgs_lat * 180.0) / ((a * (1 - ee)) / (magic * sqrtmagic) * PI)
gcj_lon = wgs_lon + dwgs_lon
gcj_lat = wgs_lat + dwgs_lat
gcj = [ gcj_lon gcj_lat ]
return gcj
def transformlon(selflo
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 1214 2018-04-25 10:25 test.py
文件 4315 2018-04-25 10:24 GpsConvert.py
- 上一篇:C# 考试管理系统
- 下一篇:C#图书管理系统增 删 改 查 功能都有
评论
共有 条评论