标记没有出现,我读了文档,但我找不到问题,有人可以帮我PLZ吗?
继承人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);
}
答案 0 :(得分:31)
我的猜测是你的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);
}