码迷,mamicode.com
首页 > Windows程序 > 详细

关于百度地图API批量转换成坐标的方法

时间:2014-10-11 18:38:16      阅读:346      评论:0      收藏:0      [点我收藏+]

标签:io   os   ar   java   for   数据   sp   on   cti   

 

下面的代码思路是:从页面获取馆Id数组,将其数组通过ajax提交到服务器,服务器返回馆的ID,馆名,和馆地址;

再循环地址,获取每个地址的坐标,并将馆ID和其坐标对应起来,提交到服务器更新,转换失败的显示到页面上。

只记录了部分js代码~

<script type="text/javascript">

 

$(function () {
$("#Iposition").click(function () {
ArrayIdTwo();
});
});

var map = new BMap.Map("waiMap"); //创建地图对象
var localSearch = new BMap.LocalSearch(map); 
var keywordArray = new Array(); //存放转换成功后的参数数组
var keyword = new Array(); //存放馆地址数组
var vId = "";             //
var successParm = ""; //用来获取成功的参数
var vAdress = "";
var index = 0;

 

function ArrayIdTwo() {

//获取选中的馆Id
$("#RpBody .tabshow input[type=‘checkbox‘]").each(function(index) {
if ($(this).attr("checked") == "checked") {
vId += $(this).parent().parent(‘td‘).next("td").html().trim() + ",";
}
});
//传参ID,返回馆地址
$.ajaxSetup({ async: false });
$.getJSON("handler/changeBaidu.ashx?callback=?", { "action": "getLibraryId", id: vId }, function(data) {
if (data == "0") return;
for (var i = 0; i < data.length; i++) {
if (i == data.length - 1) {
vAdress += data[i].Id + ":" + data[i].Name + ":" + data[i].Adress;

} else {
vAdress += data[i].Id + ":" + data[i].Name + ":" + data[i].Adress + ",";
}
}
});
var vAdressObj = vAdress.split(","); //切割成每个馆的参数
var adress = "";

for (var j = 0; j < vAdressObj.length; j++) { //循环输出地址数组
adress = vAdressObj[j].split(":");
keyword.push(adress[2]);
keywordArray.push(adress[0]);   //馆ID数组
}
searchBd(); 
}

function searchBd() {

var searchAdd = keyword[index];
setTime();
localSearch.search(searchAdd);
localSearch.setSearchCompleteCallback(function (searchResult) {
var poi = searchResult.getPoi(0);
if (poi == "" || poi == null) { //转换失败,抓取馆名
document.getElementById("error").innerHTML += "转换失败的馆ID:" + keywordArray[index-1] + "、" + searchAdd + ": error" + "</br>";
} else {
successParm += keywordArray[index-1] + "," + poi.point.lng + "," + poi.point.lat + "|";
document.getElementById("result").innerHTML += keywordArray[index - 1] + "、" + searchAdd + ":" + poi.point.lng + "," + poi.point.lat + "</br>";
}
});
}

function setTime() {
if (index < keyword.length) {
setTimeout(window.searchBd, 500);
index++;
} else {
//转换后将变量都清空,防止数据重复
vId = "";
vAdress = "";
index = 0;
keyword = [];
keywordArray = [];
$.getJSON("handler/changeBaidu.ashx?callback=?", { "action": "update", successParm: successParm }, function (data) {
if (data == "0") return;
if (data == "1") {
successParm = ""; //转换后将变量都清空,防止数据重复
alert("坐标更新完成");
}
});
}
}

</script>

关于百度地图API批量转换成坐标的方法

标签:io   os   ar   java   for   数据   sp   on   cti   

原文地址:http://www.cnblogs.com/banyan-rong/p/4019305.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!