我试图在我的网页上嵌入一个带有标记的谷歌地图。 但如果我使用以下代码, 我将得到一个未定义的警告信息 。
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);
}
如果我在代码Adress的功能下 做警报, 它正确显示纬度和经度。
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;?>");
}
谁能找出问题所在吗?