gmaps4rails

add marker with Google-Maps-for-Rails

我是研究僧i 提交于 2019-12-02 00:53:18
I was playing with https://github.com/apneadiving/Google-Maps-for-Rails and i'd like to clear all the marker on a map and add a new one at the position clicked by the user on the map, I added the following code in my page <script type="text/javascript" charset="utf-8"> function gmaps4rails_callback() { google.maps.event.addListener(Gmaps4Rails.map, 'click', function(object){ alert(object.latLng); }); </script> And in this way i can see an alert with the lat and long value, now how can i delete the old markers and create a new marker and place it on the map? If you want to clear markers created

How do I make an infowindow automatically display as open with Google-Maps-for-Rails

戏子无情 提交于 2019-12-02 00:48:25
I want to display a map with the infowindow box automatically displayed for the single marker on the page, much like http://code.google.com/apis/maps/documentation/javascript/examples/map-coordinates.html I've tried to code a callback function to accomplish this, but it's just not working for me. <% content_for :scripts do %> <script type="text/javascript" charset="utf-8"> Gmaps.map.callback = function() { if (Gmaps.map.markers.length == 1) { var marker = Gmaps.map.markers[0]; var infowindow = marker.infowindow; infowindow.open(Gmaps.map, marker); } } </script> <% end %> Your code is almost

Gmaps4rails : Setting map width and height

Deadly 提交于 2019-12-01 15:19:20
Reading the gmaps4rails gem documentation, I didn't find any way to set the map width and height. Is there any way to do this ? I should have given further details about this. I'll make an installation rake task to copy css and javascript in the Rails app. Well, for now, simply override this in your css (I assume you didn't change the map id). #gmaps4rails_map { width: 800px; height: 400px; } If you want it to work, beware to include your css after the yield(:head) <%= yield :head %> <%= stylesheet_link_tag "your css" %> The answer by @apenadving didn't work for me, assuming that the map div

gmaps4rails replaceMarkers not working (javascript)

谁说我不能喝 提交于 2019-12-01 12:20:10
stack details ruby 1.9.2p180, rails 3.0.9, gmaps4rails 1.0.2, jquery.json-2.3.min.js Background I am a newbie to gmaps4rails and really like the gem. All is working well so far, but I am trying to update markers dynamically for the first time. I am doing the following in application.js: var markers_json = $.toJSON(markers_array); Gmaps.map.replaceMarkers(markers_json); This does not work and gives the following error Uncaught TypeError: Cannot read property 'position' of undefined extendBoundsWithMarkers in gmaps4rails.googlemaps.js:204 Gmaps4Rails.adjustMapToBounds in gmaps4rails.base.js:443

gmaps4rails replaceMarkers not working (javascript)

不问归期 提交于 2019-12-01 11:01:42
问题 stack details ruby 1.9.2p180, rails 3.0.9, gmaps4rails 1.0.2, jquery.json-2.3.min.js Background I am a newbie to gmaps4rails and really like the gem. All is working well so far, but I am trying to update markers dynamically for the first time. I am doing the following in application.js: var markers_json = $.toJSON(markers_array); Gmaps.map.replaceMarkers(markers_json); This does not work and gives the following error Uncaught TypeError: Cannot read property 'position' of undefined

gmaps4rails single marker auto zoom

本秂侑毒 提交于 2019-12-01 08:17:18
I am trying to follow the answer here to zoom out a bit (by default) when a single marker is displayed on the map. I have tried the code below, and have a working map generating, but changing setZoom has no effect. Also, I receive the following error from firebug (below code). <%= gmaps("markers" => {"data" => @json, "options" => {"auto_zoom" => false} }) %> <% content_for :scripts do %> <script type="text/javascript" charset="utf-8"> function gmaps4rails_callback() { if (Gmaps4Rails.markers.length == 1) { //only one marker, choose the zoom level you expect Gmaps4Rails.map.setZoom(5); } else{

gmaps4rails - update dynamically the markers from the database on the map without refresh the page

只谈情不闲聊 提交于 2019-12-01 06:43:06
Hello I building Live bus tracking Rails app. I displayed very well my markers from the database on my Google Map in Rails 4 with the gmaps4rails gem. Controller: @hash = Gmaps4rails.build_markers(@vehicle_trackings) do |track, marker| marker.lat track.latitude marker.lng track.longitude marker.picture({ url: "/images/Bus Filled-30.png", width: 50, height: 50 }) end View: <div id='map' style='width: 100%; height: 500px;'></div> <script> handler = Gmaps.build('Google'); handler.buildMap({ provider: {}, internal: {id: 'map'}}, function(){ markers = handler.addMarkers(<%=raw @hash.to_json %>);

gmaps4rails single marker auto zoom

[亡魂溺海] 提交于 2019-12-01 05:46:22
问题 I am trying to follow the answer here to zoom out a bit (by default) when a single marker is displayed on the map. I have tried the code below, and have a working map generating, but changing setZoom has no effect. Also, I receive the following error from firebug (below code). <%= gmaps("markers" => {"data" => @json, "options" => {"auto_zoom" => false} }) %> <% content_for :scripts do %> <script type="text/javascript" charset="utf-8"> function gmaps4rails_callback() { if (Gmaps4Rails.markers

Google maps autocomplete js is working on localhost but not on heroku

心已入冬 提交于 2019-11-30 23:55:52
I'm a junior ruby on rails developer. I developed a web app that uses Google maps javascript API and I use the autocomplete function on a form input. The autocomplete works fine on localhost but does not work anymore after deploying on heroku. Here is my html.erb below. For your perfect information, the form is in the page footer. This form is partially hidden and the only visible part corresponds to a button used to upload a video file. Once this button has been clicked and the video file has been chosen, I display a modal containing the rest of the form. That's where the 'text_field_tag'

Displaying a polygon with gmaps4rails

痴心易碎 提交于 2019-11-30 16:03:17
Ruby noob here. Trying to display a list of points as a polygon on a google map using the gmaps4rails gem (awesome gem by the way). Any suggestions based on code sample below would be much appreciated! I can see the outline for the map, but no map and no polygon. Update: this code has been updated and the problem is solved. Class Schoolpoint is a list of lat/long pairs that belong to School In my controller: @polyjson = [] schoolpoints = [] Schoolpoint.where(:school_id => params[:id]).each do |point| schoolpoints << { :lng => point.longitude, :lat => point.latitude} end @polyjson =