【问题标题】:Error with markers标记错误
【发布时间】:2012-09-18 13:39:32
【问题描述】:

我试图在一个位置的地图上放置一个标记,但它给了我错误的选项,但如果我单独加载地图它工作正常

hier 是我的代码

<script type="text/javascript">
    //var map;
    function initialize() {  if (GBrowserIsCompatible()) {
            var lat = parseFloat(document.getElementById("FormView1_LatitudeLabel").textContent);
            var lng = parseFloat(document.getElementById("FormView1_LongitudeLabel").textContent);


            // Creating a map

                    // Creating a LatLng object containing the coordinate for the center of the map  
                    var latlng = new google.maps.LatLng(lat, lng);
                    // Creating an object literal containing the properties we want to pass to the map  
                    var options = {
                        zoom: 7,
                        center: latlng,
                        mapTypeId: google.maps.MapTypeId.ROADMAP,
                    };
                    // Calling the constructor, thereby initializing the map  
                    var map = new google.maps.Map(document.getElementById('map'), options);

                    var marker = new google.maps.Marker({
                        position: new google.maps.LatLng(lat, lng),
                        map: map,
                        title: 'My workplace',
                        clickable: false,
                        icon: 'img/factory.png'
                    });
                }
  }   
 </script>

【问题讨论】:

    标签: javascript asp.net google-maps


    【解决方案1】:

    GBrowserIsCompatible() 是 V2 方法,但您的其余代码是 V3,您必须决定单个 API 版本。

    【讨论】:

      【解决方案2】:

      我真的不知道你想要什么,但是

      marker.setMap(map);
      

      将在地图上显示您的标记。

      map.panTo(marker.getPosition())
      

      您可以将地图平移到标记处。

      请参阅https://developers.google.com/maps/documentation/javascript/reference#Marker 了解更多信息。

      【讨论】:

        【解决方案3】:

        此处最后一项的尾随逗号将导致 Internet Explorer 出错:

        var options = {
                                zoom: 7,
                                center: latlng,
                                mapTypeId: google.maps.MapTypeId.ROADMAP,
                            };
        

        应该是:

        var options = {
                                zoom: 7,
                                center: latlng,
                                mapTypeId: google.maps.MapTypeId.ROADMAP
                            };
        

        【讨论】:

          猜你喜欢
          • 2015-05-28
          • 2011-05-05
          • 2014-02-10
          • 1970-01-01
          • 1970-01-01
          • 2021-02-23
          • 2014-03-17
          • 2010-09-24
          • 2015-03-25
          相关资源
          最近更新 更多