How do I make an infowindow automatically display as open with Google-Maps-for-Rails
Your code is almost perfect. Except that instead of:
infowindow.open(Gmaps.map, marker);
You should have:
infowindow.open(Gmaps.map.map, marker);
Indeed, Gmaps.map is a container, Gmap.map.map is the google object.
I know these names are confusing. Sorry.
PS: be sure to put this code under the gmaps call in your view.
Get marker infowindow using gmaps4rails
instead of marker.infowindow.open
use marker.infowindow.render_to_string
refer this link (https://github.com/apneadiving/Google-Maps-for-Rails/wiki/Controller)
Make map marker direct link onclick for gmaps4rails
For this kind of needs, I pass a block to the gmaps4rails
method in the controller (doc here):
@json = User.all.to_gmaps4rails do |user, marker|
marker.json "\"id\": #{user.id}"
# or
marker.json "\"link\": #{method_to_create_link}"
end
This way I can have any additional information I need to create a link or anything.
That said, you could update your listener this way:
base_url = "whatever you need";
google.maps.event.addListener(marker, 'click', function(){
window.location(base_url + marker.id);
// or
window.location(marker.link);
});
Passing paramters from rails views to jquery (gmap)
You need to create a helper function that returns a string containing the map JavaScript using the parameters you specify.
In your app/helpers/controllername_helper.rb file:
def show_map(lat, long, zoom)
"$('#map').gMap({ markers: [{ latitude: #{lat}, longitude: #{long}, zoom: #{zoom} });"
end
Then in your view app/views/controllername/actionname, call it using the same code you referenced in your question:
<script type="text/javascript">
<%= show_map ("47.66","9.56","6") %>
</script>
Drag and update location - how to do this?
There are many errors in your code. Hard to explain one by one.
Here is a solution suggestion.
Basically when you use
handler.getMap()
its already a google maps object, so dont do:
handler.getMap().serviceObject
Add a carriage return into a Google Maps Snippet
You will have to create your own info window View
using GoogleMap.setInfoWindowAdapter
. The default info window implementation seems to remove newlines.
gmaps4rails gem: to_gmaps4rails method undefined
You're using code from v1.x and 2.x.
to_gmaps4rails
has been removed from the code base. So your first shot was ok:
def index
@hash = Gmaps4rails.build_markers(TelemetryRecording.all) do |telemetry_recording, marker|
marker.lat telemetry_recording.latitude
marker.lng telemetry_recording.longitude
marker.title telemetry_recording.delivery_unit.driver.full_name
marker.infowindow telemetry_recording.delivery_unit.driver.full_name
end
respond_with @hash
end
and in the js
<script type="text/javascript">
handler = Gmaps.build('Google');
handler.buildMap({ provider: {}, internal: {id: 'map'}}, function(){
var markers = handler.addMarkers(<%=raw @hash.to_json %>);
handler.bounds.extendWith(markers);
handler.fitMapToBounds();
$('body').on('click', '#replace_markers', function(){
$.getJSON("/telemetry_recordings", function(newMarkers){
handler.removeMarkers(markers); // to remove previous markers
markers = handler.addMarkers(newMarkers);
});
});
});
});
</script>
Related Topics
Create a Titleize Method, That Excludes "Little Words"
How to Translate Arabic/Persian Numbers to English Using Ruby
Ruby on Rails - Helper Method - Undefined Method 'Log_In' in Ruby on Rails
Ruby: How to Dynamically Replace Parameters in Native Pg Gem
Placing Sub Arrays in Neat Rows
How to Seed the Production Database Using the Capistrano Gem
Download All Gems Dependencies
How to Return a Group of Sequential Numbers That Might Exist in an Array
Pageobject with Ruby - Set Text in a Text Field Only Works in the Main File
To_SQL Not Working on Update_Attributes or .Save
Bug in Implemented Tagging System
How to Get Order Username and Provisiondate for All Softlayer MAChines Using Ruby
Rails: Upload a File or Store a Url