日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問(wèn)題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
百度地圖API如何批量轉(zhuǎn)換為百度經(jīng)緯度

百度地圖API的官網(wǎng)上提供了常用坐標(biāo)轉(zhuǎn)換的示例。但是,一次只能轉(zhuǎn)換一個(gè),真的非常麻煩??!這里結(jié)合了官方的示例,自制一個(gè)批量轉(zhuǎn)換工具,供大家參考。

因?yàn)槲覜](méi)有GPS坐標(biāo),就拿谷歌坐標(biāo)做個(gè)示例了。

  首先要注意的是,百度和谷歌的經(jīng)緯度坐標(biāo)順序是相反的。

  比如,谷歌的經(jīng)緯度是

  newgoogle.maps.LatLng(39.90762965106183, 116.3786889372559)

  傳入坐標(biāo)轉(zhuǎn)換接口的百度經(jīng)緯度應(yīng)該是

  newBMap.Point(116.3786889372559,39.90762965106183)

  所以,我建立一個(gè)數(shù)組,存放轉(zhuǎn)換前的經(jīng)緯度。創(chuàng)建百度的坐標(biāo)點(diǎn),但是用谷歌的經(jīng)緯度。

 
 
 
 
  1.   //注意:百度和谷歌的經(jīng)緯度坐標(biāo)順序是相反的。
  2.   varpoints = [newBMap.Point(116.3786889372559,39.90762965106183),
  3.   newBMap.Point(116.38632786853032,39.90795884517671),
  4.   newBMap.Point(116.39534009082035,39.907432133833574),
  5.   newBMap.Point(116.40624058825688,39.90789300648029),
  6.   newBMap.Point(116.41413701159672,39.90795884517671)
  7.   ];

  然后調(diào)用官方公布的接口

  BMap.Convertor.transMore(points,2,callback);

  自己對(duì)這個(gè)坐標(biāo)轉(zhuǎn)換接口做了修改,讓它可以多次返回結(jié)果。注意看注釋部分。

  據(jù)說(shuō),百度坐標(biāo)轉(zhuǎn)換接口,有50次/秒的限制。

 
 
 
 
  1.   functiontransMore(points,type,callback){
  2.   for(varindex inpoints){
  3.   if(index >50){return;}
  4.   varxyUrl = "http://api.map.baidu.com/ag/coord/convert?from=" + type +
  5.   "&to=4&x=" + points[index].lng + //這里要循環(huán)讀入數(shù)組points的lng數(shù)據(jù),直到points.length完畢。
  6.   "&y=" + points[index].lat +
  7.   "&callback=callback";
  8.   //動(dòng)態(tài)創(chuàng)建script標(biāo)簽
  9.   load_script(xyUrl);
  10.   }
  11.  }

  進(jìn)過(guò)上一步,坐標(biāo)就轉(zhuǎn)換好了。成為百度坐標(biāo)了。但這時(shí)的百度坐標(biāo)是加密的??床欢?/p>

  好在,我們可以直接利用這些加密的編碼創(chuàng)建出Marker標(biāo)注點(diǎn)。獲取到對(duì)象后,直接使用即可。

 
 
 
 
  1.   functioncallback(xyResult){
  2.   if(xyResult.error != 0){return;}//出錯(cuò)就直接返回;
  3.   varpoint = newBMap.Point(xyResult.x, xyResult.y);
  4.   varmarker = newBMap.Marker(point);
  5.   map.addOverlay(marker);
  6.   map.setCenter(point);//由于寫了這句,可以每一個(gè)被轉(zhuǎn)的點(diǎn)都是中心點(diǎn)的過(guò)程
  7.   }

  到這里,批量轉(zhuǎn)換就講完啦~~

  下面說(shuō)說(shuō)我自己添加的其他功能:如何獲取地圖上的坐標(biāo)點(diǎn)。

  如何獲取地圖上的坐標(biāo)點(diǎn),經(jīng)緯度?

  先說(shuō)說(shuō)谷歌的:給地圖添加事件,點(diǎn)擊地圖后直接彈出。

 
 
 
 
  1.   google.maps.event.addListener(map, 'click', function(e) {
  2.   alert(e.latLng);
  3.   });

  在說(shuō)說(shuō)百度的,也是給地圖添加事件。

 
 
 
 
  1.   map.addEventListener("click",function(e){
  2.   alert(e.point.lng + "," + e.point.lat);
  3.   });

  大家發(fā)現(xiàn)谷歌和百度有什么不同了沒(méi)有?

  對(duì)了,谷歌的經(jīng)緯度像是封裝在一起了樣。而百度的經(jīng)緯度是分開(kāi)地~~~

  全部源代碼:

  有兩個(gè)文件,一個(gè)是htm,另一個(gè)是修改后的官方坐標(biāo)轉(zhuǎn)換js。

  批量轉(zhuǎn)換.htm

 
 
 
 
  1.   
  2.   
  3.   
  4.   
  5.   
  6. 批量轉(zhuǎn)換坐標(biāo)
  7.   
  8.   
  9.   (據(jù)說(shuō)有50次/秒的限制哦)
  10.   
  11.   
  12.   

    谷歌地圖

  13.   
  •   

    鼠標(biāo)點(diǎn)擊的谷歌坐標(biāo)是:

  •   
  •   
  •   
  •   

    百度地圖

  •   
  •   

    鼠標(biāo)點(diǎn)擊的百度坐標(biāo)是:(

  •   
  •   
  •   
  •   
  •   
  •   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 + //這里要循環(huán)讀入數(shù)組points的lng數(shù)據(jù),直到points.length完畢。
  •   "&y=" + points[index].lat +
  •   "&callbackcallback=callback";
  •   //動(dòng)態(tài)創(chuàng)建script標(biāo)簽
  •   load_script(xyUrl);
  •   }
  •   }
  •   windowwindow.BMap = window.BMap || {};
  •   BMap.Convertor = {};
  •   BMap.Convertor.transMore = transMore;
  •   })();

  • 網(wǎng)站欄目:百度地圖API如何批量轉(zhuǎn)換為百度經(jīng)緯度
    標(biāo)題網(wǎng)址:http://m.5511xx.com/article/dhgohoh.html