I am trying to embed a google map with markers in my webpage. But I am getting an undefined alert message if I use the following code
var infowindow = null;
var geocoder;
$(document).ready(function () { initialize(); });
function codeAddress(address) {
geocoder = new google.maps.Geocoder();
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
//alert(results[0].geometry.location);
return (results[0].geometry.location);
}
});
}
function initialize() {
default_location = codeAddress("<?php echo $location;?>");
alert(default_location);
}
Instead of that If i am doing the alert with in the codeAdress function as below it is correctly showing the latitude and longitude.
var infowindow = null;
var geocoder;
$(document).ready(function () { initialize(); });
function codeAddress(address) {
geocoder = new google.maps.Geocoder();
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
alert(results[0].geometry.location);
}
});
}
function initialize() {
codeAddress("<?php echo $location;?>");
}
Can somebody Identify whats the problem? I am new to javascripts