2014-09-26 41 views
0

我有此代碼..工作正常。添加自定義圖像後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

+0

最新生成的HTML? – apneadiving 2014-09-26 07:37:41

+0

更新的問題與html – Remco 2014-09-26 08:19:19

回答

2

替換:

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

有了:

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

他們必須是數字

+0

謝謝!作品!! – Remco 2014-09-26 08:37:26

相關問題