I have got a function that returns the coordinates of a valid address but im having some difficulties is its an inavlid address. I was hoping to get a null value for pos1,which I set in the function if geocode fails to find a valid address.But I'm getting undefined,I know Im doing something really stupid but just cant figure what it is.
function fnCalculate(){
var pos1=getCordinates(document.getElementById("address1").value));
alert(pos1);
}
function getCordinates(address){
var loc;
if(address){
geocoder.geocode({ 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
loc=results[0].geometry.location;
}
else {
loc=null;
}
});
}
return loc;
}