【发布时间】:2019-01-18 21:05:15
【问题描述】:
我想用select过滤google maps api中json数据中的两个属性。
在这里,我正在研究开发人员谷歌的示例。我的问题出在 java 文件中的过滤器中。
我想过滤掉地震的震级和状态。我还没有找到方法来做到这一点。
有人可以帮帮我吗?
提前致谢
请看:http://jsfiddle.net/Alisson_BRA/9dzj49op/5/
完整的 JSON:https://developers.google.com/maps/documentation/javascript/examples/json/earthquake_GeoJSONP.js
HTML:
<html>
<head>
<style>
<link rel="stylesheet" href="style.css">
</style>
</head>
<body>
<script>
var gmarkers1 = [];
var markers1 = [];
var map;
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
zoom: 2,
center: new google.maps.LatLng(2.8,-187.3),
mapTypeId: 'terrain',
streetViewControl: false,
mapTypeControl: false
});
var script = document.createElement('script');
script.src = 'https://developers.google.com/maps/documentation/javascript/examples/json/earthquake_GeoJSONP.js';
document.getElementsByTagName('head')[0].appendChild(script);
}
window.eqfeed_callback = function(results) {
for (var i = 0; i < results.features.length; i++) {
var coords = results.features[i].geometry.coordinates;
var latLng = new google.maps.LatLng(coords[1],coords[0]);
var marker = new google.maps.Marker({
position: latLng,
map: map
});
}
}
gmarkers1.push(marker1);
filterMarkers = function (category) {
for (i = 0; i < markers1.length; i++) {
marker = gmarkers1[i];
if (marker.category == category || category.length === 0) {
marker.setVisible(true);
}
else {
marker.setVisible(false);
}
}
}
</script>
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap">
</script>
<div class="mapWrap">
<div class="investCast">
<select id="mag" onchange="filterMarkers(this.value);">
<option value="">Selected the magnitude</option>
<!-- value="4.5=<" Is this correct? I want to load all the values less or equal than 4.5 -->
<option value="4.5=<">Less than or equal 4.5</option>
<!-- value="4.6 to 4.9=<" Is this correct? I want to load all the values between 4.6 to 4.9 -->
<option value="4.6 to 4.9">Between 4.6 and 4.9</option>
<!-- value="4.6 to 4.9=<" Is this correct? I want to load all the values greater or equal 5 -->
<option value=">=5">Greater than or equal 5</option>
</select>
</div>
</div>
<div class="mapWrap">
<div class="investCast">
<select id="status" onchange="filterMarkers(this.value);">
<option value="">Selected the status</option>
<option value="REVIEWED">REVIEWED</option>
<option value="AUTOMATIC">AUTOMATIC</option>
<option value="PUBLISHED">PUBLISHED</option>
</select>
</div>
</div>
<div id="map"></div>
</body>
</html>
【问题讨论】:
标签: javascript json google-maps select google-maps-api-3