Search code examples
ruby-on-railsrubyruby-on-rails-3google-mapsgmaps4rails

gmaps4rails1.5.1-Geocoding not working


Location added to table. But missing latitude/longitude. So no marker added to the map.

class Location < ActiveRecord::Base
  validates :priority,:addr,:presence=>true
  validates :priority,:numericality=>{:greater_than_or_equal_to =>1,:less_than_or_equal_to =>6}
  default_scope :order=>'priority'
  acts_as_gmappable :lat=>'lat',:lng=>'lng'

  def gmaps4rails_address
    self.addr
  end

  def gmaps4rails_infowindow
    "<h4>Target priority: #{priority}</h4>" << "<h4>Address: #{addr}</h4>" << "<h4>Latitude: #{lat}</h4>" << "<h4>Longitude: #{lng}</h4>"
  end

 def gmaps4rails_marker_picture
  {
      "picture" => "/images/#{priority%7}.jpg",
      "width" => "30",
      "height" => "30"
  }
  end
end

After new location added


Solution

  • Simply set gmaps to false to trigger geocoding (as the doc tells)