javascript - Find address recursively from latitudes and longitudes in google map api -
i have latitudes , longitudes want find out addresses.
function onsuccess(response) { showlatlng(0, json.parse(response.d).table, json.parse(response.d).table.length); } where json.parse(response.d).table contains result set.
function showlatlng(index, resultset, totallen) { var lat = resultset[index].x; var lng = resultset[index].y; var latlng = new google.maps.latlng(lat, lng); new google.maps.geocoder().geocode({ 'latlng': latlng }, function (results, status) { if (status == google.maps.geocoderstatus.ok) { if (results[0]) { var z = " <tr>" + "<td>" + results[0].formatted_address + "</td>" + "</tr>"; $("#result").append(z); if (index < totallen) { showlatlng(index + 1, resultset, totallen); } } } }); } this code working 4 5 times stops , no error in firebug. please give me better way this.
edit: lucas absolutely right.
previously have used loop timeout below
$.each(json.parse(response.d).table, function (index, value) { settimeout(function () { showlatlng(index , value.x, value.y); }, (index + 1) * 7000); }); but reason (because think working on async call) skipping results.
pass latitude , longitude value script
function getaddress() { var lat = parsefloat(document.getelementbyid("txtlatitude").value); var lng = parsefloat(document.getelementbyid("txtlongitude").value); var latlng = new google.maps.latlng(lat, lng); var geocoder = geocoder = new google.maps.geocoder(); geocoder.geocode({ 'latlng': latlng }, function (results, status) { if (status == google.maps.geocoderstatus.ok) { if (results[1]) { alert("location: " + results[1].formatted_address); } } }); }
Comments
Post a Comment