I have JavaScript function call to changeMapLocation
function where in it I want to return the variables lat
and long1
. I have some problem in code to return those two variables and alert in function call.
var sample = changeMapLocation(state);
alert(sample.lat1);
alert(sample.lat2);
function changeMapLocation(state) {
var addressval=state;
var address;
var url;
var googleUrl= "http://maps.google.com/maps/api/geocode/json?";
var sensor = "&sensor=false";
if(addressval != null && addressval !="" && addressval.length!=0) {
address = "address="+encodeURIComponent(addressval);
$.ajax({
url:googleUrl+address+sensor,
type:"POST",
dataType:"json",
success:function(longlatJson) {
var jsonObj = JSON.parse(JSON.stringify(longlatJson));
var lat = jsonObj.results[0].geometry.location.lat;
var long1 = jsonObj.results[0].geometry.location.lng;
alert(lat);
alert(long1);
//var latlng = new google.maps.LatLng(lat,long1);
//alert(latlng);
},
error:function(){alert("unable to conect to google server");}
});
}
return(lat1:lat,lat2:long1);
}