在百度地图api,经纬度怎么转换成百度坐标
展开全部
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type"content="text/html; charset=gb2312"/>
<script type="text/javascript"src="changeMore.js"></script>
<title>批量转换坐标</title>
</head>
<body>
<input onclick="magic();"value="批量转换"type="button"/>(据说有50次/秒的限制哦)<hr />
<div style="clear:both">
<div style="float:left;">
<h4>谷歌地图</h4>
<div style="width:520px;height:340px;border:1px solid gray"id="map_canvas"></div>
<p>鼠标点击的谷歌坐标是:<span id="info"></span></p>
<script type="text/javascript"src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
functioninitialize() {varmyOptions ={
zoom: 14,
center: newgoogle.maps.LatLng(39.90861722866082, 116.39679921252446),
mapTypeId: google.maps.MapTypeId.ROADMAP
};varmap =newgoogle.maps.Map(document.getElementById('map_canvas'),myOptions);
google.maps.event.addListener(map, 'click', function(e) {
document.getElementById("info").innerHTML =e.latLng;
});varmarker1 =newgoogle.maps.Marker({
position: newgoogle.maps.LatLng(39.90762965106183, 116.3786889372559),
map: map
});varmarker2 =newgoogle.maps.Marker({
position: newgoogle.maps.LatLng(39.90795884517671, 116.38632786853032),
map: map
});varmarker3 =newgoogle.maps.Marker({
position: newgoogle.maps.LatLng(39.907432133833574, 116.39534009082035),
map: map
});varmarker4 =newgoogle.maps.Marker({
position: newgoogle.maps.LatLng(39.90789300648029, 116.40624058825688),
map: map
});varmarker5 =newgoogle.maps.Marker({
position: newgoogle.maps.LatLng(39.90795884517671, 116.41413701159672),
map: map
});
}
google.maps.event.addDomListener(window, 'load', initialize);</script>
</div>
<div style="float:left;">
<h4>百度地图</h4>
<div style="width:520px;height:340px;border:1px solid gray"id="container"></div>
<p>鼠标点击的百度坐标是:(<span id="info2"></span>)</p>
<script type="text/javascript"src="http://api.map.baidu.com/api?v=1.2"></script>
<script type="text/javascript">
varmap =newBMap.Map("container");
map.centerAndZoom(newBMap.Point(116.404, 39.915), 15);vari;varmarkers =[];
map.addEventListener("click",function(e){
document.getElementById("info2").innerHTML =e.point.lng +","+e.point.lat;
});//注意:百度和谷歌的经纬度坐标顺序是相反的。
varpoints =[newBMap.Point(116.3786889372559,39.90762965106183),newBMap.Point(116.38632786853032,39.90795884517671),newBMap.Point(116.39534009082035,39.907432133833574),newBMap.Point(116.40624058825688,39.90789300648029),newBMap.Point(116.41413701159672,39.90795884517671)
];functioncallback(xyResult){ if(xyResult.error !=0){return;}//出错就直接返回;varpoint =newBMap.Point(xyResult.x, xyResult.y);varmarker =newBMap.Marker(point);
map.addOverlay(marker);
map.setCenter(point);//由于写了这句,可以每一个被转的点都是中心点的过程
}functionmagic(){
BMap.Convertor.transMore(points,2,callback);
}</script>
</div>
</div>
</body>
</html>
changeMore.js
//2011-7-25 zhangying
(function(){
functionload_script(xyUrl, callback){
varhead = document.getElementsByTagName('head')[0];
varscript = document.createElement('script');
script.type = 'text/javascript';
script.src = xyUrl;
//借鉴了jQuery的script跨域方法
scriptscript.onload = script.onreadystatechange = function(){
if((!this.readyState || this.readyState === "loaded" || this.readyState === "complete")){
callback &&callback();
//Handle memory leak in IE
scriptscript.onload = script.onreadystatechange = null;
if( head &&script.parentNode ) {
head.removeChild( script );
}
}
};
//Use insertBefore instead of appendChild to circumvent an IE6 bug.
head.insertBefore( script, head.firstChild );
}
functiontransMore(points,type,callback){
for(varindex inpoints){
if(index >50){return;}
varxyUrl = "http://api.map.baidu.com/ag/coord/convert?from=" + type +
"&to=4&x=" + points[index].lng + //这里要循环读入数组points的lng数据,直到points.length完毕。
"&y=" + points[index].lat +
"&callbackcallback=callback";
//动态创建script标签
load_script(xyUrl);
}
}
windowwindow.BMap = window.BMap || {};
BMap.Convertor = {};
BMap.Convertor.transMore = transMore;
})();
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询