ウェブページにマーカー付きの Google マップを埋め込もうとしています。しかし、次のコードを使用すると、未定義の警告メッセージが表示されます
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);
}
その代わりに、以下のように codeAdress 関数でアラートを実行している場合、緯度と経度が正しく表示されます。
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;?>");
}
誰かが問題を特定できますか? 私はJavaScriptが初めてです