我正在关注谷歌地图api并添加以下代码但未显示标记
function initialize() {
var myLatlng = new google.maps.LatLng(27.7000, 85.3333);
var map_canvas = document.getElementById('map_canvas');
var map_options = {
center: new google.maps.LatLng(27.7000, 85.3333),
zoom: 12,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
// To add the marker to the map, use the 'map' property
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title:"Hello World!"
});
// To add the marker to the map, call setMap();
marker.setMap(map);
var map = new google.maps.Map(map_canvas, map_options)
}
google.maps.event.addDomListener(window, 'load', initialize);
答案 0 :(得分:0)
您在向其添加标记后创建地图,因此此时为空
var map = new google.maps.Map(map_canvas, map_options);
marker.setMap(map);
你可能有一些javascript错误,所以请查看控制台日志