Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/67.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
Ruby on rails Gmaps4Rails V2设置可见_Ruby On Rails_Gmaps4rails - Fatal编程技术网

Ruby on rails Gmaps4Rails V2设置可见

Ruby on rails Gmaps4Rails V2设置可见,ruby-on-rails,gmaps4rails,Ruby On Rails,Gmaps4rails,我认为这应该很容易,但我尝试的每一件事都不起作用。我想做的是添加代码,如果设置了review参数,则隐藏标记。不幸的是,对于Gmaps4Rails V2,我在隐藏所有标记时遇到了麻烦 <script src="//maps.google.com/maps/api/js?v=3.13&amp;sensor=false&amp;libraries=geometry" type="text/javascript"></script> <script src

我认为这应该很容易,但我尝试的每一件事都不起作用。我想做的是添加代码,如果设置了review参数,则隐藏标记。不幸的是,对于Gmaps4Rails V2,我在隐藏所有标记时遇到了麻烦

<script src="//maps.google.com/maps/api/js?v=3.13&amp;sensor=false&amp;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>

handler=Gmaps.build('Google');
buildMap({provider:{},internal:{id:'map'}},function(){
if(导航器.地理位置)
navigator.geolocation.getCurrentPosition(displayOnMap);
markers=handler.addMarkers();
handler.bounds.extendWith(markers);
handler.fitMapToBounds();
_.每个(标记、功能(索引){
标记[index].hide();
});
功能显示地图(位置){
homeposition=handler.addMarker({
纬度:位置坐标纬度,
lng:position.coords.longitude
});
handler.map.centerOn(homepostion);
};
});

一如既往地提前感谢您

您从
addMarker
获得的所有标记都具有
show
hide
功能


如果您使用clusterer,那就另当别论了,请从我尝试使用的
标记[4].hide()中获得灵感
在没有任何成功的情况下测试函数非常感谢,这非常有帮助。不幸的是,我仍然无法解决我的问题。我用最新的更改更新了代码<代码>..each(标记,函数(索引){markers[index].hide();})没有按我预期的方式工作是的,当然,看看你使用它们的方式