About Baidu Map API batch conversion to coordinate method

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.