0
我有我所分配的ID的「地址」到我的頁面上的元素:檢索地址,並用它創建谷歌地圖
<p id="address">1600 Pennsylvania Ave NW, Washington, DC 20500, United States</p>
現在我想從它創建一個谷歌地圖使用以下內容:
<script type="text/javascript">
var gecoder, map;
var address = document.getElementById('address').innerHTML;
function googlemap(address) {
geocoder = new google.maps.Geocoder();
geocoder.geocode({ 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var myOptions = {
zoom: 8,
center: results[0].geometry.location,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
}
});
}
</script>
但是,這不會返回任何內容。我得到一個空白。任何想法我做錯了什麼?