Rectangle 27 0

if it is only marker of the map:

var lat = Gmaps.map.markers[0].lat;
var lng = Gmaps.map.markers[0].lng;
var centerpoint = new google.maps.LatLng(lat, lng);
Gmaps.map.map.setCenter(centerpoint);

ruby on rails - gmaps4rails shows marker just off map when map inside ...

ruby-on-rails ruby-on-rails-3 google-maps ruby-on-rails-3.2 gmaps4rails
Rectangle 27 0

Jim's answer was probably right when he posted it. But as of now the right way to do it would be :

var centerpoint = new google.maps.LatLng(lat_value, long_value);
Gmaps.map.map.setCenter(centerpoint);

ruby on rails - In gmaps4rails, how do I move the map so the marker is...

ruby-on-rails ruby ruby-on-rails-3 google-maps gmaps4rails
Rectangle 27 0

I figured it out after some research. I'd still be curious to know how to NOT have to center if the marker is visible on the map.

var centerpoint = new google.maps.LatLng(lat_value, long_value);
Gmaps4Rails.map.setCenter(centerpoint)

edit: Found answer to how to not center map every time. Pseudo code version. 1. Get values from Gmaps4Rails.map.getBounds(). 2. Use resulting ta and la values to see if the marker is within those values. 3. If marker is outside of those values, center map, otherwise place marker without centering map.

ruby on rails - In gmaps4rails, how do I move the map so the marker is...

ruby-on-rails ruby ruby-on-rails-3 google-maps gmaps4rails
Rectangle 27 0

What you expect is automatically done as long as you pass the auto_adjust setting to true. See here.

Then, you should just use the js function Gmaps4Rails.add_markers described here.

ruby on rails - In gmaps4rails, how do I move the map so the marker is...

ruby-on-rails ruby ruby-on-rails-3 google-maps gmaps4rails
Rectangle 27 0

Gmaps4rails.build_markers(object) do |user, marker|
     marker.lat user.latitude
     marker.lng user.longitude
     marker.infowindow user.location
     marker.picture({
        :url     => "/img/blank.png",
        :width   => 32,
        :height  => 32
        })
     marker.json({:title => user.title})
  end

ruby on rails - How to show own image as marker on google map ? gmaps4...

ruby-on-rails ruby-on-rails-4 gmaps4rails