Recently made its own website, call Baidu Map JS API, on the page display some coordinate points. The problem is that when the coordinate point exceeds 10, convertor.translate (Temppointarr, 1, 5, translatecallback) after execution, the state of the data in Translatecallback is not 0, It should be that the GPS longitude and latitude conversion is not completed, resulting in coordinate points will not be added to the map display. Do not know the reason, look at the API document should be able to find the answer, helpless installed AIP Broadband, now Baidu map of the JS API page can not open. It is possible to solve this problem by dividing the coordinate transformation into a group of 10.
varGroups = 0; //callback function after the coordinate conversion is completeTranslatecallback =function(data) {if(Data.status = = 0) { for(vari = 0; i < data.points.length; i++) { varMarker =NewBmap.marker (Data.points[i]); varLabel =NewBmap.label (Groups * + I,{offset:NewBmap.size (20,-10)}); Marker.setlabel (label); //add Baidu labelMap.addoverlay (marker); } groups++; Map.setcenter (Data.points[i-1]); //alert ("The Center is the:" + (i-1) + "th point"); } Else{alert ("Data status is not 0"); }} setTimeout (function(){ varConvertor =NewBmap.convertor (); varn = 10; Alert ("The Totall number of points is:" +pointarr.length); varremain = pointarr.length% 10; varRounds = (pointarr.length-remain)/10; Alert (rounds+ "groups of points and" + remain + "points to translate"); varTemppointarr = []; varindex = 0; for(varR = 0; R < rounds; r++) {Temppointarr= []; for(vari = 0; I < n; i++) {alert ("The index of point:" +index); Temppointarr.push (Pointarr[index]); Index++; } convertor.translate (Temppointarr,1, 5, Translatecallback); } Temppointarr= []; for(vari = 0; I < remain; i++) {alert ("The index of point:" +index); Temppointarr.push (Pointarr[index]); Index++; } convertor.translate (Temppointarr,1, 5, Translatecallback); }, 1000);
Use of the Baidu map JavaScript API