【问题标题】:Adding Marker to Google Map向谷歌地图添加标记
【发布时间】:2014-02-07 17:55:40
【问题描述】:

我正在使用 Javascript API 创建地图,但在显示标记时遇到了一些问题。

我已按照本教程创建地图,效果很好:

https://developers.google.com/maps/tutorials/fundamentals/adding-a-google-map

然后我按照本教程添加了标记,但它没有加载:

https://developers.google.com/maps/documentation/javascript/examples/marker-simple

这是我的代码:

            <script>
        function initialize() {
            var map_canvas = document.getElementById('map_canvas');
            var map_options = {
            center: new google.maps.LatLng(43.643296, -79.408475),
            zoom: 15,
            mapTypeId: google.maps.MapTypeId.ROADMAP }
            var map = new google.maps.Map(map_canvas, map_options, marker);
            var marker = new google.maps.Marker({
            position: myLatlng,
            map: map,
            title:"Hello World!" });
            }

            google.maps.event.addDomListener(window, 'load', initialize);

            </script>

【问题讨论】:

    标签: javascript api google-maps


    【解决方案1】:

    这一行

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

    错了。 mapconstructor 只有两个参数。应该是

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

    并且myLatlng 没有定义。因此,您可以将代码更改为:

    function initialize() {
        myLatlng = new google.maps.LatLng(43.643296, -79.408475);
    
        var map_canvas = document.getElementById('map');
        var map_options = {
            center: myLatlng,
            zoom: 15,
        mapTypeId: google.maps.MapTypeId.ROADMAP }
        var map = new google.maps.Map(map_canvas, map_options);
    
        var marker = new google.maps.Marker({
            position: myLatlng,
            map: map,
            title:"Hello World!" });
    }
    

    【讨论】:

      【解决方案2】:

      【讨论】:

        猜你喜欢
        • 2013-04-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-08-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多