上海城市坐标
這個詞我也是這個項目才聽說,然后百度了個轉(zhuǎn)換方法,其實對不對我也不知道,因為我壓根不知道上海城市坐標(biāo)從哪兒看
貼貼代碼
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);elsegcdist = 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;}} elsegcbrg = 0;hor = gcdist * rearth;xx = hor * Math.sin(temp);yy = hor * Math.cos(temp);return [xx, yy];}講真啊? 我連兩個參數(shù)哪個是東京,哪個是北緯我都忘了
lat應(yīng)該是北緯,lon那就是東經(jīng)了
然后返回值也是第一個是北緯 ,第二個是東經(jīng)。
這個項目還用了用百度地圖,不過也就是打開地圖,定位下而已
比如這樣
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");// 創(chuàng)建Map實例//var point = new BMap.Point(121.446235, 31.169152); // 創(chuàng)建點(diǎn)坐標(biāo)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); // 創(chuàng)建標(biāo)注map.addOverlay(marker); // 將標(biāo)注添加到地圖中//map.panTo(new_point);setTimeout(function () {map.panTo(new_point);}, 200);}
轉(zhuǎn)載于:https://www.cnblogs.com/suzu/p/5776000.html
總結(jié)
- 上一篇: matlab 万能,matlab 万能实
- 下一篇: wireshark使用教程 linux,