添加自定义图像后,gmaps4rails标记无法点击

时间:2014-09-26 07:27:34

标签: ruby-on-rails ruby-on-rails-4 gmaps4rails

我有这个代码..工作正常。

控制器:

@locations = Location.where(:country_id => @country.id)


    @hash = Gmaps4rails.build_markers(@locations) do |location, marker|
       marker.lat location.latitude
       marker.lng location.longitude
       marker.infowindow location.description
    end

查看:

<script type=text/javascript> 

    handler = Gmaps.build('Google');
    handler.buildMap({ provider: {}, internal: {id: 'map'}}, function(){
      markers = handler.addMarkers(<%=raw @hash.to_json %>);
      handler.bounds.extendWith(markers);
      handler.fitMapToBounds();


    });
</script>

现在我要添加自定义标记(类别)显示每个位置属于一个类别。

@hash = Gmaps4rails.build_markers(@locations) do |location, marker|
       marker.lat location.latitude
       marker.lng location.longitude
       marker.picture({
       "url" => "/assets/" + location.category + ".png",
       "width" =>  "30",        
       "height" => "30"
       })
       marker.infowindow location.description
    end

HTML

handler = Gmaps.build('Google');
                handler.buildMap({ provider: {}, internal: {id: 'map'}}, function(){
                  markers = handler.addMarkers([{"lat":43.3851,"lng":12.3856,"picture":{"url":"/assets/apartment.png","width":"25","height":"25"},"title":"Apartment Magazzino of Villa Il Frantoio is located in Umbria at the edge of a small \"borgo\" (a group of houses standing together). The house lies in a peaceful setting, but is centrally located at the same time? it is only a 10 minute drive to the shops and restaurants. \r\n \r\n","infowindow":"Apartment Magazzino of Villa Il Frantoio is located in Umbria at the edge of a small \"borgo\" (a group of houses standing together). The house lies in a peaceful setting, but is centrally located at the same time? it is only a 10 minute drive to the shops and restaurants. \r\n \r\n"},{"lat":43.3851,"lng":12.3856,"picture":{"url":"/assets/apartment.png","width":"25","height":"25"},"title":"Apartment Magazzino of Villa Il Frantoio is located in Umbria at the edge of a small \"borgo\" (a group of houses standing together). The house lies in a peaceful setting, but is centrally located at the same time? it is only a 10 minute drive to the shops and restaurants","infowindow":"Apartment Magazzino of Villa Il Frantoio is located in Umbria at the edge of a small \"borgo\" (a group of houses standing together). The house lies in a peaceful setting, but is centrally located at the same time? it is only a 10 minute drive to the shops and restaurants"});
              handler.bounds.extendWith(markers);
              handler.fitMapToBounds();


            });

这适用于标记(类别的不同基础),但标记不再可点击。我究竟做错了什么?

thanks..remco

1 个答案:

答案 0 :(得分:2)

替换:

   "width" =>  "30",        
   "height" => "30"

使用:

   "width" =>  30,        
   "height" => 30

他们必须是数字