javascript 谷歌地图标记未显示 API v3
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15026447/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 23:12:20 来源:igfitidea点击:
Google maps marker not showing up API v3
提问by Ramon Vasconcelos
The marker isnt showing up, i read the docs but i cant find the problem, can somebody help me plz?
标记没有出现,我阅读了文档,但我找不到问题,有人可以帮我吗?
heres the js:
继承人js:
function initialize() {
var mapOptions = {
center: new google.maps.LatLng(-8.064903, -34.896872),
zoom: 16,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
var marker = new google.maps.Marker({
position: location,
title:"Hello World!",
visible: true
});
marker.setMap(map);
}
回答by alestanis
My guess is that your location
object is not defined. Try setting your marker position to the same LatLng as your map center and see if it works:
我的猜测是您的location
对象未定义。尝试将标记位置设置为与地图中心相同的 LatLng,看看它是否有效:
function initialize() {
latLng = new google.maps.LatLng(-8.064903, -34.896872)
var mapOptions = {
center: latLng,
zoom: 16,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
var marker = new google.maps.Marker({
position: latLng,
title:"Hello World!",
visible: true
});
marker.setMap(map);
}