在使用地理編碼初始化谷歌地圖時遇到一些問題。第一個問題是在$ gmap字符串中使用任何逗號,第二個問題是獲取「gmap_initialize未定義」。我知道這個功能以外的所有東西都是正確的,任何想法?在加載頁面時將地址傳遞給谷歌地圖
<?php $gmap = "Prague, Czech Republic"; ?>
<script type="text/javascript">
function gmap_initialize() {
var geocoder = new google.maps.Geocoder();
geocoder.geocode({ 'address': <?php echo $gmap; ?>}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var options = {
zoom: 16,
position: results[0].geometry.location,
center: results[0].geometry.location,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"), options);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
</script>
謝謝Broady,這是修復(忘了更新我的答案)。好的呼喚也逃跑。 – Alex 2010-11-15 08:16:39