Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 显示数据库中的标记_Javascript_Google Maps_Google Maps Api 3 - Fatal编程技术网

Javascript 显示数据库中的标记

Javascript 显示数据库中的标记,javascript,google-maps,google-maps-api-3,Javascript,Google Maps,Google Maps Api 3,下面的java脚本将在GoogleMap中显示标记。这里我添加了控制 按钮位于左下角。我的输出显示所有标记。但当我点击控制按钮时,我需要从数据库中过滤一些标记。我该怎么做 <style type="text/css"> body { font: normal 10pt Helvetica, Arial; } #map { width: 100%; height: 100%; border: 0px; padding: 0px; }

下面的java脚本将在GoogleMap中显示标记。这里我添加了控制 按钮位于左下角。我的输出显示所有标记。但当我点击控制按钮时,我需要从数据库中过滤一些标记。我该怎么做

 <style type="text/css">
            body { font: normal 10pt Helvetica, Arial; }
            #map { width: 100%; height: 100%; border: 0px; padding: 0px; }
    </style>
    <script src="http://maps.google.com/maps/api/js?v=3&sensor=false" type="text/javascript"></script>
    <script type="text/javascript">
        var icon = new google.maps.MarkerImage("images/icons/icon.png",
                       new google.maps.Size(32, 32), new google.maps.Point(0, 0),
                       new google.maps.Point(16, 32));
        var center = null;
        var map = null;
        var currentPopup;
        var bounds = new google.maps.LatLngBounds();

        //adding multiple marker
        function addMarker(lat, lng, info) {
            var pt = new google.maps.LatLng(lat, lng);
            bounds.extend(pt);
            var marker = new google.maps.Marker({
                position: pt,
                icon: icon,
                map: map});
            var popup = new google.maps.InfoWindow({
                content: info,
                maxWidth: 300 });
            google.maps.event.addListener(marker, "click", function() {
                if (currentPopup != null) {
                    currentPopup.close();
                    currentPopup = null;
                }
                popup.open(map, marker);
                currentPopup = popup;});
            google.maps.event.addListener(popup, "closeclick", function() {
                map.panTo(center);
                currentPopup = null;
            });
        }
        function HomeControl(controlDiv, map) {

          // Set CSS styles for the DIV containing the control
          // Setting padding to 5 px will offset the control
          // from the edge of the map
          controlDiv.style.padding = '5px';

          // Set CSS for the control border
          var controlUI = document.createElement('div');
          controlUI.style.backgroundColor = 'white';
          controlUI.style.borderStyle = 'solid';
          controlUI.style.borderWidth = '2px';
          controlUI.style.cursor = 'pointer';
          controlUI.style.textAlign = 'center';
          controlUI.title = 'Click to Filter';
          controlDiv.appendChild(controlUI);

          // Set CSS for the control interior
          var controlText = document.createElement('div');
          controlText.style.fontFamily = 'Arial,sans-serif';
          controlText.style.fontSize = '12px';
          controlText.style.paddingLeft = '4px';
          controlText.style.paddingRight = '4px';
          controlText.innerHTML = '<b>GYM</b>';
          controlUI.appendChild(controlText);

          // Setup the click event listeners: simply set the map to
          google.maps.event.addDomListener(controlUI, 'click', function() {     

                //need to filter Markers
                //$query = mysql_query("SELECT * FROM mytable where availability = false");


          });
        }
        function initMap() {
            map = new google.maps.Map(document.getElementById("map"), {
                center: new google.maps.LatLng(0, 0),
                zoom: 14,
                mapTypeId: google.maps.MapTypeId.ROADMAP,
                mapTypeControl: false,
                mapTypeControlOptions: {
                    style: google.maps.MapTypeControlStyle.HORIZONTAL_BAR
                },
                navigationControl: true,
                navigationControlOptions: {
                    style: google.maps.NavigationControlStyle.SMALL}});
            <?php
                $query = mysql_query("SELECT * FROM mytable ");
                while ($row = mysql_fetch_array($query)){
                    $regno      =   $row['id'];
                    $latitude   =   $row['latitude'];
                    $longitude  =   $row['longitude'];  
                    echo "addMarker($longitude, $latitude,'<b>$id</b>');";
                }
            ?>
            center = bounds.getCenter();
            map.fitBounds(bounds);

            var homeControlDiv = document.createElement('div');
            var homeControl = new HomeControl(homeControlDiv, map);
            homeControlDiv.index = 1;
            map.controls[google.maps.ControlPosition.LEFT_BOTTOM].push(homeControlDiv);

        }
    </script>

----
<body onLoad="initMap()" style="margin:0px; border:0px; padding:0px;">
创建标记时,将其推送到阵列中并推送每个标记对象。 单击按钮,循环遍历标记数组,并对每个标记调用setMapnull。 使用过滤器再次查询数据库 下面是一些快速代码,以便您了解:

// Create an array of markers
var markers = [];

// Create your map and all the stuff you need

// Bind the event listener
google.maps.event.addDomListener(controlUI, 'click', function() {

    // First delete all your markers
    deleteMarkers();

    // Query your database again and add each marker as you did in the first place
});

// Function to delete the markers
function deleteMarkers() {

    for (var i = 0; i < markers.length; i++) {

        // Remove each marker from map
        markers[i].setMap(null);
    }
}

function addMarker() {

    // Create each marker object

    var marker = new google.maps.Marker({
        map: map,
        // Your other marker properties here
    });

    // Push new marker to the markers array
    markers.push(marker);
}

函数HomeControl在地图上创建一个名为“gym”的按钮,其单击事件与addDomListener事件一起工作。没有功能HomeControl地图显示所有制造商。我需要在begging加载所有生成器,一旦我单击gym按钮,只有健身房位置生成器才会显示。$query=mysql\u querySELECT*FROM mytable;将显示all和$query=mysql\u querySELECT*FROM mytable,其中availability=false;好主意,我会检查一下,让你知道