我认为这应该很简单,但我尝试的每件事都行不通。我想要做的是添加隐藏标记的代码(如果设置了review参数)。不幸的是,使用Gmaps4Rails V2,我无法隐藏所有标记。
<script src="//maps.google.com/maps/api/js?v=3.13&sensor=false&libraries=geometry" type="text/javascript"></script>
<script src='//google-maps-utility-library-v3.googlecode.com/svn/tags/markerclustererplus/2.0.14/src/markerclusterer_packed.js' type='text/javascript'></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.6.0/underscore.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/gmaps4rails/2.1.2/gmaps4rails.js"></script>
</div>
<div style='width: 100%;'>
<div id="map" style='width: 100%; height: 400px;'></div>
</div>
<script type="text/javascript">
handler = Gmaps.build('Google');
handler.buildMap({ provider: {}, internal: {id: 'map'}}, function(){
if(navigator.geolocation)
navigator.geolocation.getCurrentPosition(displayOnMap);
markers = handler.addMarkers (<%=raw @hash.to_json %>);
handler.bounds.extendWith(markers);
handler.fitMapToBounds();
_.each(markers, function(index){
markers[index].hide();
});
function displayOnMap(position){
homepostion = handler.addMarker({
lat: position.coords.latitude,
lng: position.coords.longitude
});
handler.map.centerOn(homepostion);
};
});
</script>
一如既往地谢谢你
答案 0 :(得分:0)
您从addMarker
获得的所有标记都包含show
和hide
个函数see code
如果您使用群集器,这是另一个故事,请从removeMarker function
中获取灵感