有没有办法用jQuery过滤谷歌地图的位置变量?
例:
点击带有ID car的链接,过滤ID car的所有字符串。 点击身份证汽车会在地图上隐藏带有ID船的所有字符串,并在地图中仅显示带有ID车的字符串。
有可能吗?
function initialize() {
var locations = [
['<strong>Firm 1</strong><br />1111 Country<br />Street<br /><br />', 47.6801806,8.7499505, 1, id car here?? ],
['<strong>Firm 2</strong><br />2222 Country<br />Street<br /><br />', 47.6801806,8.7499505, 2, id boat here?? ],
];
var map = new google.maps.Map(document.getElementById('map_canvas'), {
zoom: 10,
center: new google.maps.LatLng(47.603786, 9.055737),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var infowindow = new google.maps.InfoWindow();
var marker, i;
for (i = 0; i < locations.length; i++) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][1], locations[i][2]),
map: map,
icon: new google.maps.MarkerImage('/assets/templates/style/images/iconKarte.png')
});
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infowindow.setContent(locations[i][0]);
infowindow.open(map, marker);
}
})(marker, i));
}
}
</script>
<div id="map_canvas" style="width:750px;height:500px;"></div>
答案 0 :(得分:0)
您需要执行以下as shown in this JsFiddle with a lot of redundant code
过滤的实际代码是:
{clear:{}},
{ action: 'addMarkers',
marker:{
values:ulmarkerspeople,
options:{
draggable: false,
icon:'http://mapicons.nicolasmollet.com/wp-content/uploads/mapicons/shape-default/color-ffc11f/shapecolor-color/shadow-1/border-dark/symbolstyle-white/symbolshadowstyle-dark/gradient-no/male-2.png'
}}
我正在使用gmap3清空空对象,因为它允许清除标签或ID。如果您使用的是Google地图v3 API,请在重绘标记之前使用{action:'clear'}
清除地图。