gmaps4rails中的自定义标记不会出现

时间:2016-04-10 05:52:34

标签: javascript ruby-on-rails google-maps google-maps-markers gmaps4rails

我尝试按照https://github.com/apneadiving/Google-Maps-for-Rails中的指南操作,但我的自定义图标仍然无法加载。

 @hash = Gmaps4rails.build_markers(@terminals) do |terminal, marker|
          marker.lat terminal.latitude
          marker.lng terminal.longitude
         marker.picture({
            "url" => "/assets/marker.png",
            "width" =>  30,        
            "height" => 30
            })
        end

image marker.png位于assets / images。

构建地图:

<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();
  handler.getMap().setZoom(13);
  handler.getMap().setOptions({styles: [{"featureType":"water","stylers":[{"saturation":43},{"lightness":-11},{"hue":"#0088ff"}]},{"featureType":"road","elementType":"geometry.fill","stylers":[{"hue":"#ff0000"},{"saturation":-100},{"lightness":99}]},{"featureType":"road","elementType":"geometry.stroke","stylers":[{"color":"#808080"},{"lightness":54}]},{"featureType":"landscape.man_made","elementType":"geometry.fill","stylers":[{"color":"#ece2d9"}]},{"featureType":"poi.park","elementType":"geometry.fill","stylers":[{"color":"#ccdca1"}]},{"featureType":"road","elementType":"labels.text.fill","stylers":[{"color":"#767676"}]},{"featureType":"road","elementType":"labels.text.stroke","stylers":[{"color":"#ffffff"}]},{"featureType":"poi","stylers":[{"visibility":"off"}]},{"featureType":"landscape.natural","elementType":"geometry.fill","stylers":[{"visibility":"on"},{"color":"#b8cb93"}]},{"featureType":"poi.park","stylers":[{"visibility":"on"}]},{"featureType":"poi.sports_complex","stylers":[{"visibility":"on"}]},{"featureType":"poi.medical","stylers":[{"visibility":"on"}]},{"featureType":"poi.business","stylers":[{"visibility":"simplified"}]}]});
});
</script>

地图:

    <div id="map"class="col-md-8" style="height: 100vh; background-color: #E4E2E1;">
    </div>

它是如何出现的: enter image description here

如果没有控制器中的marker.picture,它的外观如何: enter image description here

1 个答案:

答案 0 :(得分:0)

尝试将marker.picture更改为:

marker.picture({
   url: ActionController::Base.helpers.asset_path('marker.png'),
   width:  '30',        
   height: '30'
})