【问题标题】:Custom Marker in gmaps4rails won't appeargmaps4rails 中的自定义标记不会出现
【发布时间】:2016-04-10 05:52:34
【问题描述】:

我尝试按照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

图像 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>

它的外观:

在控制器中没有marker.picture的情况下:

【问题讨论】:

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


【解决方案1】:

尝试将您的marker.picture 更改为:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多