0

我是 JavaScript 和 Google Maps API v3 的新手。我正在 ASP.Net 页面中尝试开发人员指南示例代码。地图按预期显示,但未加载标记。如果有人能发现我的错误,我将不胜感激:

<style type="text/css">
    html, body, #map_canvas { margin: 0; padding: 0; height: 100%; }
</style>
<script type="text/javascript"
    src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
    var map;
    var myLatlng = new google.maps.LatLng(-41.2954168187213,174.767133718655 )
    function initialize() {
        var myOptions = {
            zoom: 4,
            center: myLatlng,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        map = new google.maps.Map(document.getElementById("map_canvas"),
        myOptions);
    }

    var marker = new google.maps.Marker({
        position: myLatlng,
        map: map,
        title: "Hello World!"
    });
    // The following set map made no difference.
    //The constructor above should have been enough?
    //marker.setMap(map);
    //google.maps.event.addDomListener(window, 'load', initialize);
</script>
<body  onload="initialize()">
    <div id="map_canvas"></div>
</body>
4

1 回答 1

2

尝试将标记代码放在初始化函数中。否则标记看不到创建的地图。

于 2012-05-05T22:54:12.597 回答