GoogleアプリケーションをWebアプリケーションに統合しようとしていますが、コードで「google not defined」というエラーが表示されます。Maps APIを統合する際に「googleが定義されていません」
誰かが私を理解するのに役立つことができますか?前もって感謝します。
</head><script src="http://maps.google.com/maps/api/js?key=AIzaSyAdXcTNKKaje1AtGQq32SwOMJ5Um-EE5GU " async="" defer="defer" type="text/javascript"></script>
<body> <div id="map" style="width: 400px; height: 300px;"></div><script type="text/javascript">
function LoadGoogle()
{ if(typeof google != 'undefined' && google && google.load)
{
var address = 'UK';
var map = new google.maps.Map(document.getElementById('map'), {
mapTypeId: google.maps.MapTypeId.TERRAIN,
zoom: 6
});
var geocoder = new google.maps.Geocoder();
geocoder.geocode({
'address': address
},
function(results, status) {
if(status == google.maps.GeocoderStatus.OK) {
new google.maps.Marker({
position: results[0].geometry.location,
map: map
});
map.setCenter(results[0].geometry.location);
}
});
}
else
{
setTimeout(LoadGoogle, 30);
}
}
LoadGoogle(); </script></body>
まだ同じエラーを取得し、また、これを試してみました。
var map = new google.maps.Map(document.getElementById('map'), {
mapTypeId: google.maps.MapTypeId.TERRAIN,
zoom: 6
});
var geocoder = new google.maps.Geocoder();
geocoder.geocode({
'address': address
},
function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
new google.maps.Marker({
position: results[0].geometry.location,
map: map
});
map.setCenter(results[0].geometry.location);
}
});
使用するGoogleマップ 'callback'機能を呼び出すことはありません。 Googleマップスクリプトが読み込まれると、メソッドを呼び出します。 –