javascript - how to get more that +10/11 LatLng values from markers -
i have array localizations ("street, city, postalcode, province, country"). want have string lat , lng values each localization, ("#lat.value|lng.value#lat2.value|lng2.value.." etc). use google api geocoder. geocoder has annoying limit 10~11 localizations once. how can 100 lat&lng values 100 localization? tried sleep() funcion, doesn't work. function in js.
function sleep(time){ time = time * 1000; var start = (new date()).gettime(); while(true){ alarm = (new date()).gettime(); if(alarm - start > time){ break; } } } (..) var mystring = ""; var address = <%=testing %> var arrayaddress = address.split("%"); (var = 0; < arrayaddress.length-1; i++) { sleep(0); geocoder = new google.maps.geocoder(); geocoder.geocode( { 'address': arrayaddress[i]}, function(results, status) { if (status == google.maps.geocoderstatus.ok) { map.setcenter(results[0].geometry.location); var marker = new google.maps.marker({ map: map, position: results[0].geometry.location }); var zmiennalat = marker.getposition().lat(); var zmiennalng = marker.getposition().lng(); mystring = mystring + "#" + zmiennalat + "|" + zmiennalng; } else { mystring = mystring + "#" + "er" + "|" + "er"; //alert("geocode not successful following reason: " + status); } if (i == arrayaddress.length-1) { var dsa = mystring; document.getelementbyid("<%=hfwysokosc.clientid%>").value = mystring; document.getelementbyid("<%=hfszerokosc.clientid%>").value = dsa; document.getelementbyid("<%=updatebutton1.clientid %>").click(); } }); } //
then, result example:
er|er#34.42342|16.4323#23.32131|43.54545# etc..
always @ first localizations error decoding (if more 10 places in array). why? why not @ last localizations?
resuming: how can more 10 lat|lng values in stirng loop?
thanks!
editthanks, work nice !
but there problem. string mystring showing slowly.. how repair it? , refreshing when marker setting on map - maybe not problem, 100-150 markers have wait few long minutes mystring value.. posibility show more faster mystring value?
var mystring = ""; var address = <%=testing %> alert(address); var arrayaddress = address.split("%"); (function nextstep(i){ if( >= arrayaddress.length-1 ){ return; } geocoder = new google.maps.geocoder(); geocoder.geocode( { 'address': arrayaddress[i]}, function(results, status) { if (status == google.maps.geocoderstatus.ok) { map.setcenter(results[0].geometry.location); var marker = new google.maps.marker({ map: map, position: results[0].geometry.location }); var zmiennalat = marker.getposition().lat(); var zmiennalng = marker.getposition().lng(); mystring = mystring + zmiennalat + "|" + zmiennalng + "#"; } else { mystring = mystring + "er" + "|" + "er" + "#"; //alert("geocode not successful following reason: " + status); } }); settimeout(function(){ nextstep(i+1); }, 800); var dsa = mystring; document.getelementbyid("<%=hfszerokosc.clientid%>").value = dsa; document.getelementbyid("<%=updatebutton1.clientid %>").click(); })(0);
update
function nextstep(i){ if( >= arrayaddress.length-1 ){ return; } // code }); settimeout(function(){ nextstep(i+1); }, 1000); };
then
<button type="button" onclick="nextstep(0)">click me!</button>
and error is:
nextstep not defined
what wrong?
instead of for-loop, try this:
//............... //............... var mystring = ""; var address = <%=testing %> var arrayaddress = address.split("%"); //modification-----begin (function nextstep(i){ if( >= arrayaddress.length-1 ){ return; } //----------------- //for-loop body here //------------------ // settimeout(function(){ nextstep(i+1); }, 500); })(0); //modification-----end //............... //...............
update: if want run nextstep
function,only when button clicked,then modify above code this:
function nextstep(i){ ///// };
then,when onclick
triggered, call nextstep(0)
.
Comments
Post a Comment