百度地图坐标和⾕歌地图坐标互换(采⽤⾼德api,⾼德坐标
和⾕歌坐标⼀致)
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>百度地图坐标和⾕歌地图坐标互换</title>
<script type="text/javascript" src="api.map.baidu/api?v=1.3"></script>
<script type="text/javascript" src="developer.baidu/map/jsdemo/demo/convertor.js"></script>
<script type="text/javascript" src="webapi.amap/maps?v=1.2"></script>
</head>
<body>
<div>
百度地图坐标和⾕歌地图坐标互换(采⽤⾼德api,⾼德坐标和⾕歌坐标⼀致)</div>
<div id="bmap" >
</div>
<div id="gmap" >
</div>
<div class="field" >
<div class="input">
<label for="input-small">
百度经度:</label><input type="text" value="116.403801" id="bmaplng" name="blng" />
<label for="input-small">
百度維度:</label>
<input type="text" value="39.915573" id="bmaplat" name="blat" />
<input type="button" value="转⾕歌" οnclick="b2g()" />
</div>
</div>
<div class="field">
<div class="input">
<label for="input-small">
⾕歌经度:</label><input type="text" value="116.397428" id="amaplng" name="lng" />
<label for="input-small">
⾕歌維度:</label>
<input type="text" value="39.90923" id="amaplat" name="lat" />
<input type="button" value="转百度" οnclick="g2b()" />
</div>
</div>
</body>
</html>
<script type="text/javascript">
var ifmarker = "";
var point;
//百度地图初始化
var bm = new BMap.Map("bmap");
var bmaplng;
var bmaplat;
point = new BMap.Point("116.403801", "39.915573");
bm.addControl(new BMap.NavigationControl());
//百度地图增加监听事件
bm.addEventListener("click", function (e) {
var pt = e.point;
if (ifmarker != "marker") {
mapreduce编程模型
addmarker_b(pt);
amaplat = 0.000000;
amaplng = 0.000000;
b2gFitLocation();
}
});
//百度地图添加点到地图中
正割函数的积分function addmarker_b(pt) {
//debugger;
bm.clearOverlays();
marker_b = new BMap.Marker(pt); // 创建标注
bm.addOverlay(marker_b); // 将标注添加到地图中
ableDragging();
marker_b.addEventListener("dragend", function (e) {
addmarker_b(Position());
});
marker_b.addEventListener("click", function (e) {
ifmarker = "marker";
});
bm.setCenter(pt);
bmaplng = pt.lng;
bmaplat = pt.lat;
}
//⾼德地图初始化
var gm, toolbar, overview, scale;
gm = new AMap.Map("gmap", {
center: new AMap.LngLat(116.397428, 39.90923),
level: 11
});
gm.plugin(["AMap.ToolBar", "AMap.OverView", "AMap.Scale"], function () {
toolbar = new AMap.ToolBar();
toolbar.autoPosition = false; //加载⼯具条
gm.addControl(toolbar);
overview = new AMap.OverView(); //加载鹰眼
gm.addControl(overview);
});
//⾼德地图监听事件
AMap.event.addListener(gm, 'click', listenerfn);
function listenerfn(e) {
addMarker_g(Lng(), Lat());
point = new BMap.Point(Lng(), Lat());
g2bFitLocation(point);
}
//⾼德地图添加点到地图中
function addMarker_g(amaplng, amaplat) {
//构建点对象
gm.clearMap();
var marker_g = new AMap.Marker({
map: gm,
position: new AMap.LngLat(amaplng, amaplat), //基点位置
食肉植物不吃肉会死吗icon: "webapi.amap/images/marker_sprite.png", //marker图标,直接传递地址url offset: { x: -8, y: -34} //相对于基点的位置
});
gm.setCenter(new AMap.LngLat(amaplng, amaplat));
//gm.setZoom(16);
integrate名词// gm.setCenter(Position());
}
//⾕歌地图转百度地图
function g2bFitLocation(pt) {
anslate(pt, 2, translateCallback);
}
//坐标转换完之后的回调函数
function translateCallback(point) {
addmarker_b(point);
}
//百度地图转换为google地图,重复调⽤b2gFitLocation(),直⾄转过来的坐标经过转换后与百度原坐标差距⼩于0.000002 var amaplat = 0.000000;
var amaplng = 0.000000;
var bm_lat = 0;
var bm_lon = 0;
var delta_lat = 0;
var delta_lon = 0;
function b2gFitLocation() {
//debugger;
if (!amaplng) amaplng = 0.000000;
if (!amaplat) amaplat = 0.000000;
var point = new BMap.Point(amaplng, amaplat);
anslate(point, 2, b2gTranslateCallback);
}
function b2gTranslateCallback(point) {
var result_lat = bmaplat || ElementById('bmaplat').value;
position和location的区别var result_lon = bmaplng || ElementById('bmaplng').value;
bm_lat = Fixed(6);
bm_lon = Fixed(6);
delta_lat = (point.lat - result_lat).toFixed(6);
delta_lon = (point.lng - result_lon).toFixed(6);
var abs_delta_lat = Math.abs(delta_lat * 1e6);
var abs_delta_lon = Math.abs(delta_lon * 1e6);
if (abs_delta_lat < 2 && abs_delta_lon < 2) {
addMarker_g(amaplng, amaplat);
} else {
amaplat = amaplat - delta_lat;
amaplng = amaplng - delta_lon;
易语言编程源码论坛b2gFitLocation();
}
}
//页⾯按钮点击
function b2g() {
var lat = ElementById('bmaplat').value;
var lng = ElementById('bmaplng').value;
point = new BMap.Point(lng, lat);
addmarker_b(point);
amaplat = 0.000000;
amaplng = 0.000000;
b2gFitLocation();
}
function g2b() {
var lat = ElementById('amaplat').value; var lng = ElementById('amaplng').value; point = new BMap.Point(lng, lat);
addMarker_g(point.lng, point.lat);
g2bFitLocation(point);
}
</script>
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论