-1

我正在关注 google map 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);
4

1 回答 1

0

您在将标记添加到地图后创建地图,因此此时它为空

    var map = new google.maps.Map(map_canvas, map_options);

    marker.setMap(map);

您可能有一些 javascript 错误,因此请查看控制台日志

于 2013-10-02T06:48:04.673 回答