<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>地图经纬度描点工具</title>
<!--
<script type="text/javascript" src="http://api.map.baidu.com/api?v=1.2"></script>
-->
<script src="http://code.jquery.com/jquery-1.8.0.min.js"></script>
<script type="text/javascript"
src="http://api.map.baidu.com/api?v=3.0&ak=百度密钥"></script>
<script src=""></script>
<script src=""></script>
<style>
li {
list-style-type: none;
height: 20px
}
ul {
background-color: #cccccc;
position: absolute;
width: 300px;
padding: 0;
left: 53px;
top: 64px;
max-height: 300px;
min-height: 50px;
}
ul:hover {
cursor: pointer;
}
</style>
</head>
<body>
<div style="width:80%;height:1000px;border:1px solid gray" id="container"></div>
<div style="right:10px;top:8px;position: absolute;width:18%; height: 650px;border:1px solid gray">
<p>
手动:<input id="startBtn" type="button" onclick="startTool();" value="开启取点工具"/>
<span>经纬度:</span><input type="button" onclick="clearLast()" value="清除最后"/>
<!-- <span>经纬度:</span><input type="button" onclick="clearAll()" value="清除所有"/>-->
</p>
<p>
搜索:<input type="input" name="addr" id="addr"/>
<input type="button" onclick="getBoundary()" value="搜索"/>
<ul>
</ul>
</p>
<hr>
<p style="padding: 0 5px;">
<textarea id="info" style="width:94%;margin:2px;max-height: 980px;min-height: 440px;overflow-y:scroll;"
></textarea>
<button onclick="copy()" style="text-align: right">文本复制</button>
<button onclick="coverage()" style="text-align: right">百度</button>
<button class="btn" onclick="openLineEdit()">开起线编辑</button>
<button class="btn" onclick="closeLineEdit()">关闭线编辑</button>
<input type="text" id="inx" style="width: 80%">
<button onclick="searchPoint()">bdto84</button>
<input type="text" id="inx1" style="width: 80%">
<button onclick="searchPoint1()">84tobd</button>
<input type="text" id="inx2" style="width: 80%">
<button onclick="searchPoint2()">84tobd</button>
</p>
</div>
</body>
</html>
<script type="text/javascript">
var CoordinateUtil = {
x_pi: 3.14159265358979324 * 3000.0 / 180.0,
//pai
pi: 3.1415926535897932384626,
//离心率
ee: 0.00669342162296594323,
//长半轴
a: 6378245.0,
//百度转国测局
bd09togcj02: function (bd_lon, bd_lat) {
var x = bd_lon - 0.0065;
var y = bd_lat - 0.006;
var z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * CoordinateUtil.x_pi);
var theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * CoordinateUtil.x_pi);
var gg_lng = z * Math.cos(theta);
var gg_lat = z * Math.sin(theta);
return {
lng: gg_lng,
lat: gg_lat
}
},
wgs84togcj02: function (lng, lat) {
var dlat = CoordinateUtil.transformlat(lng - 105.0, lat - 35.0);
var dlng = CoordinateUtil.transformlng(lng - 105.0, lat - 35.0);
var radlat = lat / 180.0 * CoordinateUtil.pi;
var magic = Math.sin(radlat);
magic = 1 - CoordinateUtil.ee * magic * magic;
var sqrtmagic = Math.sqrt(magic);
dlat = (dlat * 180.0) / ((CoordinateUtil.a * (1 - CoordinateUtil.ee)) / (magic * sqrtmagic) * CoordinateUtil.pi);
dlng = (dlng * 180.0) / (CoordinateUtil.a / sqrtmagic * Math.cos(radlat) * CoordinateUtil.pi);
var mglat = parseFloat(lat) + dlat;
var mglng = parseFloat(lng) + dlng;
return {
lng: mglng,
lat: mglat
}
},
bd09toWgs84: function (bd_lon, bd_lat) {
let bd09togcj = CoordinateUtil.bd09togcj02(bd_lon, bd_lat);
return CoordinateUtil.gcj02towgs84(bd09togcj.lng, bd09togcj.lat);
},
wgs84tobd09: function (bd_lon, bd_lat) {
let bd09togcj = CoordinateUtil.wgs84togcj02(bd_lon, bd_lat);
return CoordinateUtil.gcj02tobd09(bd09togcj.lng, bd09togcj.lat);
},
//国测局转百度
gcj02tobd09: function (lng, lat) {
var z = Math.sqrt(lng * lng + lat * lat) + 0.00002 * Math.sin(lat * CoordinateUtil.x_pi);
var theta = Math.atan2(lat, lng) + 0.000003 * Math.cos(lng * CoordinateUtil.x_pi);
var bd_lng = z * Math.cos(theta) + 0.0065;
var bd_lat = z * Math.sin(theta) + 0.006;
return {
lng: bd_lng,
lat: bd_lat
};
},
//国测局转84
gcj02towgs84: function (lng, lat) {
var dlat = CoordinateUtil.transformlat(lng - 105.0, lat - 35.0);
var dlng = CoordinateUtil.transformlng(lng - 105.0, lat - 35.0);
var radlat = lat / 180.0 * CoordinateUtil.pi;
var magic = Math.sin(radlat);
magic = 1 - CoordinateUtil.ee * magic * magic;
var sqrtmagic = Math.sqrt(magic);
dlat = (dlat * 180.0) / ((CoordinateUtil.a * (1 - CoordinateUtil.ee)) / (magic * sqrtmagic) * CoordinateUtil.pi);
dlng = (dlng * 180.0) / (CoordinateUtil.a / sqrtmagic * Math.cos(radlat) * CoordinateUtil.pi);
var mglat = lat + dlat;
var mglng = lng + dlng;
return {
lng: lng * 2 - mglng,
lat: lat * 2 - mglat
};
},
//经度转换
transformlat: function (lng, lat) {
var ret = -100.0 + 2.0 * lng + 3.0 * lat + 0.2 * lat * lat + 0.1 * lng * lat + 0.2 * Math.sqrt(Math.abs(lng));
ret += (20.0 * Math.sin(6.0 * lng * CoordinateUtil.pi) + 20.0 * Math.sin(2.0 * lng * CoordinateUtil.pi)) * 2.0 / 3.0;
ret += (20.0 * Math.sin(lat * CoordinateUtil.pi) + 40.0 * Math.sin(lat / 3.0 * CoordinateUtil.pi)) * 2.0 / 3.0;
ret += (160.0 * Math.sin(lat / 12.0 * CoordinateUtil.pi) + 320 * Math.sin(lat * CoordinateUtil.pi / 30.0)) * 2.0 / 3.0;
return ret;
},
//纬度转换
transformlng: function (lng, lat) {
var ret = 300.0 + lng + 2.0 * lat + 0.1 * lng * lng + 0.1 * lng * lat + 0.1 * Math.sqrt(Math.abs(lng));
ret += (20.0 * Math.sin(6.0 * lng * CoordinateUtil.pi) + 20.0 * Math.sin(2.0 * lng * CoordinateUtil.pi)) * 2.0 / 3.0;
ret += (20.0 * Math.sin(lng * CoordinateUtil.pi) + 40.0 * Math.sin(lng / 3.0 * CoordinateUtil.pi)) * 2.0 / 3.0;
ret += (150.0 * Math.sin(lng / 12.0 * CoordinateUtil.pi) + 300.0 * Math.sin(lng / 30.0 * CoordinateUtil.pi)) * 2.0 / 3.0;
return ret;
},
getWgs84xy: function (x, y) {
//先转 国测局坐标
var doubles_gcj = CoordinateUtil.bd09togcj02(x, y); //(x 117. y 36. )
//国测局坐标转wgs84
var doubles_wgs84 = CoordinateUtil.gcj02towgs84(doubles_gcj.lng, doubles_gcj.lat);
//返回 纠偏后 坐标
return doubles_wgs84;
}
}
let a=[{"lng":121.58022543956862,"lat":30.873823182359015},{"lng":121.58012086965347,"lat":30.87382318231677},{"lng":121.58001629973832,"lat":30.87382318227454},{"lng":121.5799117299041,"lat":30.873732984311864},{"lng":121.57980716008689,"lat":30.873732984269633},{"lng":121.57970259026968,"lat":30.8737329842274},{"lng":121.57959802045247,"l