मैं gmaps4rails के मणि का उपयोग करता हूं और नक्शे हमेशा पहले पृष्ठ पर लोड नहीं होते हैं, पुनः लोड होने के बाद यह काम करता है।
तो, मेरा कोड show.html.haml
%script{:src => "//maps.google.com/maps/api/js?v=3.13&sensor=false&libraries=geometry", :type => "text/javascript"}
%script{:src => "//google-maps-utility-library-v3.googlecode.com/svn/tags/markerclustererplus/2.0.14/src/markerclusterer_packed.js", :type => "text/javascript"}
........
.col-lg-8.col-sm-8.col-md-8.col-xs-12
#map
%br/
......
: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(16);
});
में parks_controller.rb
def show
set_park
@hash = Gmaps4rails.build_markers(@park) do |park, marker|
marker.lat park.latitude
marker.lng park.longitude
marker.infowindow park.address
end
में index.html.haml
- @parks.each do |park|
.map_index
.image_wrapper
= image_tag "http://maps.google.com/maps/api/staticmap?size=400x200&sensor=false&zoom=16&markers=#{park.latitude}%2C#{park.longitude}", class: "map_image"
%h2
= link_to park.title, park
कार्य ऐप - https://geoparks.herokuapp.com/
मुझे बताओ, कृपया, कोड में क्या बदलना या जोड़ना है?
उत्तर:
उत्तर № 1 के लिए 1मैं केवल उन लिंक को जोड़ता हूं जो नक्शे पृष्ठ पैरामीटर पर जाते हैं
"data-no-turbolink" => true
कोड = link_to p.title, park
में index.html.haml में परिवर्तित किया गया
= link_to park.title, park, "data-no-turbolink" => true