我的页面上有一个元素,我已将 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>
然而,这没有返回。我得到一个空白。知道我在做什么错吗?