Google Maps API v3。如何根据日期和时间隐藏地图上的标记时间?

时间:2012-03-15 15:50:18

标签: javascript mysql google-maps-api-3

好的,我有一个项目地图,我正在努力从mysql中提取数据。在我的数据库中,我有一个名为“周末”的列,其值为“0或1”。值“1”表示无论是一天中的哪一天或时间都显示标记。

对于所有其他标记,我需要它们隐藏起来;从周五晚上9点到周日晚上9点。除非他们在周末列中的值为“1”,否则他们会显示。

任何人都可以帮我构建这个java脚本函数吗?任何帮助将不胜感激。

这是我的代码:

//Icon Selection
    var customIcons = {
      Full: {
        icon: 'red.png'

      },
      Partial: {
        icon: 'blue.png',

      }

    };


function load() {
  var map = new google.maps.Map(document.getElementById("map"), {
    center: new google.maps.LatLng(26.075287, -80.309029),
    zoom: 12,
    mapTypeId: 'roadmap'
  });
  var infoWindow = new google.maps.InfoWindow;


  // Change this depending on the name of your PHP file
  downloadUrl("phpsqlajax_genxml2.php", function(data) {
    var xml = data.responseXML;
    var markers = xml.documentElement.getElementsByTagName("marker");
    for (var i = 0; i < markers.length; i++) {
      var Udf_DSCategory = markers[i].getAttribute("Udf_DSCategory");
      var Description = markers[i].getAttribute("Description");
      var Udf_DSLimitsTo = markers[i].getAttribute("Udf_DSLimitsTo");
      var Udf_DSType = markers[i].getAttribute("Udf_DSType");
      var Udf_DSPIONotes = markers[i].getAttribute("Udf_DSPIONotes");
      var Udf_DSApprovedBy = markers[i].getAttribute("Udf_DSApprovedBy");
    var Udf_DSLimitsOfClosure = markers[i].getAttribute("Udf_DSLimitsOfClosure");
    var ProjectName = markers[i].getAttribute("ProjectName");
    var Udf_DSDateClosureFrom = markers[i].getAttribute("Udf_DSDateClosureFrom");   
    var Udf_DSDateClosureTo = markers[i].getAttribute("Udf_DSDateClosureTo");
    var weekend = markers[i].getAttribute("weekend");               
    var point = new google.maps.LatLng(
          parseFloat(markers[i].getAttribute("UserText1")),
          parseFloat(markers[i].getAttribute("BulletinID")));

      var html = 

     "<b> Project Name: </b> " + ProjectName +  "<br/>" +"<b> Category: </b> " + Udf_DSCategory + " <br/>" + "<b> Closure Type: </b>" + Udf_DSType + "  <br/> <b> Date From: </b> " + Udf_DSDateClosureFrom + " <b>to</b> " + Udf_DSDateClosureTo + " <br/>" + "<b> Road: </b>" + Description + "<br/>" + "<b> Closure Notes: </b>" + Udf_DSPIONotes + "<br/>" + "<b> Closure Approved by: </b>" + Udf_DSApprovedBy ;


      var icon = customIcons[Udf_DSType] || {};
      var marker = new google.maps.Marker({
        map: map,
        position: point,
        icon: icon.icon,
        shadow: icon.shadow,

        }); 



      bindInfoWindow(marker, map, infoWindow, html);

    }
  });


}


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


function downloadUrl(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 doNothing() {}

1 个答案:

答案 0 :(得分:0)

关于评论,最好只从DB中获取所需的标记。

查询可能看起来像这样(可能还有很多其他方式)

SELECT * FROM `yourTable` 
   WHERE( weekends=1 
            OR
          WEEKDAY(NOW())<4 
            OR 
          (WEEKDAY(NOW())=4 AND HOUR(NOW())<18)
            OR 
          (WEEKDAY(NOW())=6 AND HOUR(NOW())>17)
        )