0

我試過按照https://github.com/apneadiving/Google-Maps-for-Rails中的指南,但是我的自定義圖標仍然無法加載。gmaps4rails中的自定義標記不會出現

@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

+0

檢查這個[SO問題](http://stackoverflow.com/questions/8498760/trouble-displaying-a-custom-marker-using-gmaps4rails)幫你 :) – KENdi

回答

0

嘗試改變你的marker.picture到:如果可以

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