javascript - store all value in variable with comma separate -
i try lat , long value url using ajax.
this:-
$(function() { var region = "rajkot,jamnagar,surat"; var cn ="in"; var array = region.split(','); for(var item in array) { var lat; $.ajax({ url: "http://services.gisgraphy.com//geocoding/geocode?address="+array[item]+"&country="+cn+"&format=json", async: false, datatype:'jsonp', success: function(data){ lat = data.result[0].lat; lng = data.result[0].lng; alert(lat); } }); }
here got latitude , longitude value.
want lat value in 1 variable comma seprate.
, lng value in variable comma seprate.
how possible.
help. thanks....
var lat = new array(), lng = new array(); var totallength = array.length; var count = 0; for(var item in array) { $.ajax({ url: "http://services.gisgraphy.com//geocoding/geocodeaddress="+array[item]+"&country="+cn+"&format=json", async: false, datatype:'jsonp', success: function(data) { count++; lat.push(data.result[0].lat); lng.push(data.result[0].lng); if (count == totallength) { var commaseperatedlat = lat.tostring(); var commaseperatedlong = lng.tostring(); } }, error: function(data) { count++;//handle } }); }
Comments
Post a Comment