2017-11-22 1 views
0

ich die gem 'gmaps4rails' installiert haben und das ist das Setup ich habe:Rails5: gem 'gmaps4rails' der Karte Google zeigt nicht

Gemfile

gem 'gmaps4rails' 
gem 'underscore-rails' 

application.js

//= require underscore 
//= require gmaps/google 

show.html.erb

<script src="//maps.google.com/maps/api/js?key=I have my api key in here"></script> 
<script src="//cdn.rawgit.com/mahnunchik/markerclustererplus/master/dist/markerclusterer.min.js"></script>  
<script src='//cdn.rawgit.com/printercu/google-maps-utility-library-v3-read-only/master/infobox/src/infobox_packed.js' type='text/javascript'></script> 

<div id="map" style='width: 400px; height: 400px;'> 

     <script> 
      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> 

     </div> 

Artikel-controller.rb

def show 
@items = Item.find(params[:id]) 
@hash = Gmaps4rails.build_markers(@items) do |item, marker| 
    marker.lat item.latitude 
    marker.lng item.longitude 
    marker.picture({ 
        :url => "http://www.google.com/mapfiles/dd-end.png", 
        :width => 32, 
        :height => 32 
       }) 
    marker.infowindow render_to_string(:partial => 'items/info_page') 
end 
    append_cur_location 
end 


def append_cur_location 
    @hash << { 
    :lat=>action[0], 
    :lng=>action[1], 
    :picture=> { 
     :url=> "http://www.google.com/mapfiles/dd-start.png", 
     :width=> 32, 
     :height=> 32 
     } 
    } 
end 

    def action 
    @lat_lng = cookies[:lat_lng].split("|") unless cookies[:lat_lng] == nil 
    end 

Es sollte auf den show.html.erb aber es ist nicht zu sehen sein !! Im Webinspektor des Browsers erhalte ich zwei Warnungen:

The page at https://localhost:3000/items/1 was allowed to display insecure content from http://www.google.com/mapfiles/dd-end.png. 
The page at https://localhost:3000/items/1 was allowed to display insecure content from http://www.google.com/mapfiles/dd-start.png. 

Irgendwelche Ideen, was hier falsch sein könnte?

+0

Sie versuchen, Inhalte anzuzeigen, aus 'http' zu' https' –

+0

beide sollten die Aktualisierung entweder 'http: //' oder 'https: // ' –

+0

eine weitere Frage, warum greifen Sie auf localhost mit' https: // '? –

Antwort

0

bereites show.html.erb mit diesem Code

<script src="//maps.google.com/maps/api/js?key=I have my api key in here"></script> 
<script src="//cdn.rawgit.com/mahnunchik/markerclustererplus/master/dist/markerclusterer.min.js"></script>  
<script src='//cdn.rawgit.com/printercu/google-maps-utility-library-v3-read-only/master/infobox/src/infobox_packed.js' type='text/javascript'></script> 

<div style='width: 800px;'> 
    <div id="map" style='width: 800px; height: 400px;'></div> 
</div> 

<script> 
    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> 
+0

Danke für die Antwort @Sachin Singh, ich aktualisiert nach Ihrem Code und immer noch nicht erscheint – Theopap

+0

@Theopap bitte versuchen Sie nicht, den aktuellen Standort an '@ Hash' anhängen und lassen Sie es mich wissen. –

Verwandte Themen