The following code idea is: Get the Library ID array from the page, the array is submitted to the server via AJAX, the server returns to the library's ID, library name, and library address;
Recycle the address, get the coordinates of each address, and the library ID and its coordinates, submit to the server update, conversion failed to display on the page.
Only part of the JS code is recorded ~
<script type= "Text/javascript" >
$ (function () {
$ ("#Iposition"). Click (function () {
Arrayidtwo ();
});
});
var map = new Bmap.map ("Waimap"); Create a Map object
var localsearch = new Bmap.localsearch (map);
var keywordarray = new Array (); Array of arguments after successful conversion
var keyword = new Array (); Repository Address Array
var vId = ""; //
var successparm = ""; Parameters used to get the success
var vadress = "";
var index = 0;
function Arrayidtwo () {
Get the selected Library ID
$ ("#RpBody. Tabshow input[type= ' checkbox ']"). each (function (index) {
if ($ (this). attr ("checked") = = "Checked") {
VId + = $ (this). Parent (). Parent (' TD '). Next ("TD"). HTML (). Trim () + ",";
}
});
Pass ID, return to library address
$.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 (","); Cut into the parameters of each pavilion
var adress = "";
for (var j = 0; J < Vadressobj.length; J + +) {//Loop output address array
adress = Vadressobj[j].split (":");
Keyword.push (adress[2]);
Keywordarray.push (Adress[0]); Library ID Array
}
SEARCHBD ();
}
function searchbd () {
var searchadd = Keyword[index];
SetTime ();
Localsearch.search (Searchadd);
Localsearch.setsearchcompletecallback (function (SearchResult) {
var poi = searchresult.getpoi (0);
if (poi = = "" | | POI = = null) {//conversion failed, grab library name
document.getElementById ("Error"). InnerHTML + = "Conversion failed Library 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 {
Empty variables after conversion to prevent duplication of data
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 = ""; Empty variables after conversion to prevent duplication of data
Alert ("Coordinate update complete");
}
});
}
}
</script>
About Baidu Map API batch conversion to coordinate method