Google地图边栏未定义变量

时间:2011-12-12 09:39:35

标签: javascript google-maps

我想在侧边栏中显示deviceid变量,

我能够提取数据并在我的地图上显示位置就好......但侧边栏显示未定义。 我是javascript的新手虽然可能会出错。

错误在哪里?

由于

<script type="text/javascript">

var deviceid;
    var point;
        var map;
    var image = 'images/mm_20_red.png';
    var url = "phpsqlajax_genxml3.php";

    function load() {
        var milan = new google.maps.LatLng(45.4636889, 9.1881408);
        var mapOptions = {
            zoom: 13,
            center: milan,
            mapTypeId: google.maps.MapTypeId.ROADMAP
            }
        map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions );

        var infoWindow = new google.maps.InfoWindow;

      GDownloadUrl(url, function(data) {
        var xml = data.responseXML;
        var markers = xml.documentElement.getElementsByTagName("marker"); 
        for (var i = 0; i < markers.length; i++) {
          var deviceid = markers[i].getAttribute("deviceid");
          var point = new google.maps.LatLng(
              parseFloat(markers[i].getAttribute("latitude")),
              parseFloat(markers[i].getAttribute("longitude")));
          var timestamp = markers[i].getAttribute("timestamp");   
          var html = "<b>" + deviceid;

          var marker = new google.maps.Marker({
            deviceid: deviceid,
            map: map,
            position: point,
            icon: image
          });

            bindInfoWindow(marker, map, infoWindow, html);

            //Creates a sidebar button for the marker
            createMarkerButton(marker);

                // START zoom
                google.maps.event.addListener(marker, 'click', function() {
                map.setZoom(16);
                });
                // END zoom
        }
      });

    }


    function bindInfoWindow(marker, map, infoWindow, html) {
      google.maps.event.addListener(marker, 'click', function() {
        infoWindow.setContent(html);
        infoWindow.open(map, marker);
      });
    }

    function GDownloadUrl(url, callback) {
      var request = window.ActiveXObject ?
          new ActiveXObject('Microsoft.XMLHTTP') :
          new XMLHttpRequest;

      request.onreadystatechange = function() {
        if (request.readyState == 4) {
          request.onreadystatechange = doNothing;
          callback(request, request.status);
        } 
      };

      request.open('GET', url, true);
      request.send(null);
    }

    function createMarkerButton(marker) {
  var ul = document.getElementById("marker_list");
  var li = document.createElement("li");
  var deviceid = marker.getTitle();
  //li.innerHTML = title;
  li.innerHTML = deviceid;
  ul.appendChild(li);

  //Trigger a click event to marker when the button is clicked.
  google.maps.event.addDomListener(li, "click", function(){
    google.maps.event.trigger(marker, "click");
  });
}   

    function doNothing() {}

</script>

0 个答案:

没有答案