看不到Google标记 [英] can't see google marker
本文介绍了看不到Google标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人可以告诉我为什么我在这张地图上看不到标记吗?
Can someone tell me why I can't see the marker on this map?
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0; padding: 0 }
#map_canvas { height: 100% }
</style>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?keykey=AIzaSyBG47z_ebM8I6Ic2-rXL8QiPN5CHCOBwco&sensor=true"></script>
<script type="text/javascript">
function initialize() {
var mapOptions = {
center: new google.maps.LatLng(37.998727,-0.686259),
zoom: 18,
minZoom: 4,
maxZoom: 13,
mapTypeId: google.maps.MapTypeId.ROADMAP,
streetViewControl: false
};
var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
}
var marker = new google.maps.Marker({
position: new google.maps.LatLng(37.998727,-0.686259),
map: map
});
</script>
<body onload="initialize()">
<div id="map_canvas" style="width:600px; height:600px;"></div>
推荐答案
在浏览器的错误控制台中查看:
Look in your browser's error console:
Uncaught ReferenceError: map is not defined
您需要公开该变量,因为map
当前在initialize()
范围之外不可见.或者,将标记代码移到initialize()
:
You need to expose that variable, since map
is not currently visible outside of the scope of initialize()
. Or, move the marker code into initialize()
:
function initialize() {
var mapOptions = {
center: new google.maps.LatLng(37.998727,-0.686259),
zoom: 18,
minZoom: 4,
maxZoom: 13,
mapTypeId: google.maps.MapTypeId.ROADMAP,
streetViewControl: false
};
var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
var marker = new google.maps.Marker({
position: new google.maps.LatLng(37.998727,-0.686259),
map: map
});
}
这篇关于看不到Google标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文