4

我正在使用谷歌地图来绘制我当地的犯罪活动。它有效,但现在我想使用同一页面中的表单过滤街道名称、日期范围、性质等。

我遵循了位于https://developers.google.com/academy/apis/maps/visualizing/earthquakes的教程。

他们使用 jsonp 提要作为数据源。

script.src = 'http://earthquake.usgs.gov/earthquakes/feed/geojsonp/2.5/week'

我创建了一个名为“process_request.php”的脚本来返回我所在地区的犯罪数据以符合要求。

我不知道如何应用我的过滤器/表单标准。所以这是我的问题......我应该使用 AJAX 来更新 window.eqfeed_callback 吗?表单操作应该是“index.php”还是“process_request.php”?我应该onsubmit="refreshMap();"在我的表格中使用吗?

 <script>
      var map;

      function initialize() {
        var mapOptions = {
          zoom: 13,
          center: new google.maps.LatLng(37.749919,-68.869871),
          mapTypeId: google.maps.MapTypeId.TERRAIN
        };

        map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions);

        // Create a <script> tag and set the USGS URL as the source.
        var script = document.createElement('script');
        // (In this example we use a locally stored copy instead.)
        // script.src = 'http://earthquake.usgs.gov/earthquakes/feed/geojsonp/2.5/week';
        script.src = 'https://example.com/crime/process_request.php';
        document.getElementsByTagName('head')[0].appendChild(script);
      }

      // Loop through the results array and place a marker for each
      // set of coordinates.
      window.eqfeed_callback = function(results) {

        var infowindow = new google.maps.InfoWindow();

        for (var i = 0; i < results.features.length; i++) {
            var coords = results.features[i].geometry.coordinates;
            var latLng = new google.maps.LatLng(coords[0],coords[1]);
            var weight_factor = results.features[i].properties.weight;

            var marker = new google.maps.Marker({
                position: latLng,
                map: map,
                icon: getCircle(weight_factor),
            });

            google.maps.event.addListener(marker,'click', (function(marker, i) {
                return function() {
                    infowindow.setContent('<strong>Address:</strong> ' + results.features[i].properties.address + "<br><strong>Total Reports:</strong> "+ results.features[i].properties.weight + "<br><strong>Nature:</strong> " + results.features[i].properties.nature);
                    infowindow.open(map, marker);
                }
            })(marker, i));

        }
      }

    function getCircle(weight_factor) {
        return {
            path: google.maps.SymbolPath.CIRCLE,
            fillColor: 'red',
            fillOpacity: .3,
            scale: weight_factor * 3, //Math.pow(2, magnitude) / Math.PI,
            strokeColor: 'white',
            strokeWeight: .8
        };
    }

   </script>
4

1 回答 1

1

我最终修改了大部分脚本并从头开始构建 json(我认为我不需要 jsonp 功能)并为表单使用 javascript 函数action

<form name="filter_form" action="javascript:drawMap(getData())" method="POST">
于 2012-11-14T02:21:58.793 回答