这个词我也是这个项目才听说,然后百度了个转换方法,其实对不对我也不知道,因为我压根不知道上海城市坐标从哪儿看
贴贴代码
function wgs84Tosh(lat, lon) { var xx, yy, r2d, tolat, tolon, rearth, PI; PI = 3.141592653589793; r2d = 57.2957795131; tolat = (31 + (14.0 + 7.55996 / 60.0) / 60.0) / r2d; tolon = (121.0 + (28.0 + 1.80651 / 60.0) / 60) / r2d; rearth = 6371006.84; var hor, frlat, frlon, gcdist, clatf, clatt, slatf, slatt, gcbrg; var dlon, cdlon, sdlon, sdist, cdist, sbrg, cbrg, temp; var intlat, intlon; intlat = lat; intlon = lon; frlat = lat / r2d; frlon = lon / r2d; clatt = Math.cos(frlat); clatf = Math.cos(tolat); slatt = Math.sin(frlat); slatf = Math.sin(tolat); dlon = frlon - tolon; cdlon = Math.cos(dlon); sdlon = Math.sin(dlon); cdist = slatf * slatt + clatf * clatt * cdlon; temp = (clatt * sdlon) * (clatt * sdlon) + (clatf * slatt - slatf * clatt * cdlon) * (clatf * slatt - slatf * clatt * cdlon); sdist = Math.sqrt(Math.abs(temp)); if ((Math.abs(sdist) > 1e-7) || (Math.abs(cdist) > 1e-7)) gcdist = Math.atan2(sdist, cdist); else gcdist = 0; sbrg = sdlon * clatt; cbrg = (clatf * slatt - slatf * clatt * cdlon); if ((Math.abs(sbrg) > 1e-7) || (Math.abs(cbrg) > 1e-7)) { temp = Math.atan2(sbrg, cbrg); while (temp < 0) { temp = temp + 2 * PI; gcbrg = temp; } } else gcbrg = 0; hor = gcdist * rearth; xx = hor * Math.sin(temp); yy = hor * Math.cos(temp); return [xx, yy]; }
讲真啊 我连两个参数哪个是东京,哪个是北纬我都忘了
lat应该是北纬,lon那就是东经了
然后返回值也是第一个是北纬 ,第二个是东经。
这个项目还用了用百度地图,不过也就是打开地图,定位下而已
比如这样
var map; function loadJScript() { var script = document.createElement("script"); script.type = "text/javascript"; script.src = "http://api.map.baidu.com/api?v=2.0&ak=×××××××××××××××&callback=init"; document.body.appendChild(script); } function init() { map = new BMap.Map("allmap");// 创建Map实例 //var point = new BMap.Point(121.446235, 31.169152); // 创建点坐标 map.centerAndZoom("上海", 17); map.enableScrollWheelZoom(true); } window.onload = loadJScript; function showmap(a, b) { map.clearOverlays(); var new_point = new BMap.Point(a, b); var marker = new BMap.Marker(new_point); // 创建标注 map.addOverlay(marker); // 将标注添加到地图中 //map.panTo(new_point); setTimeout(function () { map.panTo(new_point); }, 200); }
时间: 2024-10-14 11:06:46