Store All Value In Variable With Comma Separate
i am try to get lat and long value from the url using ajax. with this:- $(function() { var region = 'Rajkot,Jamnagar,Surat'; var cn ='IN'; var
Solution 1:
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
}
});
}
Solution 2:
var lat = new Array(), lng = new Array();
var latStr='',lonStr='';
success: function(data){
lat.push(data.result[0].lat);
lng.push(data.result[0].lng);
}
latStr = lat.join(',');
lonStr = lng.join(',');
Post a Comment for "Store All Value In Variable With Comma Separate"