apneadiving / Google-Maps-for-Rails

Enables easy Google map + overlays creation in Ruby apps
https://apneadiving.github.io/
MIT License
2.26k stars 382 forks source link

Map shown is off by few miles #170

Closed ronakg closed 11 years ago

ronakg commented 12 years ago

Hi, first of all thanks for this wonderful gem. It does make a developer's life easier.

I'm trying to use the gem in my application and it is working fine in terms of maps displayed etc. However, the marker shown on the map is off by few miles than that shown on maps.google.com.

For example, I have these fields in my app -

The coordinates that I get for this address is 12.9551537, 77.58009899999999, which is off by few miles from actual location. If I search for Ravindra Kalakshethra, Jayachamaraja Wodeyar Rd, Bangalore on Google Maps, it shows the location perfectly.

Any idea why is this happening?

This is how my model looks like -

class Event
  include Gmaps4rails::ActsAsGmappable
  include Mongoid::Document

  field :venue, :type => String
  field :street, :type => String
  field :city, :type => String
  field :longitude, :type => Float
  field :latitude, :type => Float
  field :gmaps, :type => Boolean

  acts_as_gmappable

  def gmaps4rails_address
      "#{self.venue}, #{self.street}, #{self.city}"
  end
apneadiving commented 12 years ago

I don't know, maybe there is some additional config to pass to google.

I find the same as you:

Gmaps4rails.geocode("Ravindra Kalakshethra,Jayachamaraja Wodeyar Rd, Bangalore", "in")
 => [{:lat=>12.9551537, :lng=>77.58009899999999, :matched_address=>"Jayachamaraja Wodeyar Rd, Bengaluru, Karnataka, India", 
:bounds=>{"northeast"=>{"lat"=>12.9552082, "lng"=>77.580105}, "southwest"=>{"lat"=>12.9550991, "lng"=>77.58009299999999}}, 
:full_data=>{"address_components"=>[{"long_name"=>"Bengaluru", "short_name"=>"Bengaluru", "types"=>["locality", "political"]}, {"long_name"=>"Jayachamaraja Wodeyar Rd", "short_name"=>"Jayachamaraja Wodeyar Rd", "types"=>["route"]}, {"long_name"=>"Bengaluru", "short_name"=>"Bengaluru", "types"=>["administrative_area_level_2", "political"]}, {"long_name"=>"Karnataka", "short_name"=>"Karnataka", "types"=>["administrative_area_level_1", "political"]}, {"long_name"=>"India", "short_name"=>"IN", "types"=>["country", "political"]}], "formatted_address"=>"Jayachamaraja Wodeyar Rd, Bengaluru, Karnataka, India", "geometry"=>{"bounds"=>{"northeast"=>{"lat"=>12.9552082, "lng"=>77.580105}, "southwest"=>{"lat"=>12.9550991, "lng"=>77.58009299999999}}, "location"=>{"lat"=>12.9551537, "lng"=>77.58009899999999}, "location_type"=>"APPROXIMATE", "viewport"=>{"northeast"=>{"lat"=>12.9565026302915, "lng"=>77.5814479802915}, "southwest"=>{"lat"=>12.9538046697085, "lng"=>77.5787500197085}}}, "types"=>["route"]}}] 
ulugbekov commented 12 years ago

I know the answer. It happened to me. I found lang and long myself and tried to save through gmaps4rails_address method and passed lang and long. Gmaps is either cutting last 7 digits or rounding them to 9s. Those numbers are crucial for exact location for google. Is there any way to use decimal with precision and scale to use 16 digits. If so Gmaps will be perfect tool for perfect location.

apneadiving commented 12 years ago

@ulugbekov : very interesting.

Seems like I can't do anything to fix this then, @ronakg : would you close the issue?

andeepak commented 12 years ago

Is there a fix or a workaround ?

apneadiving commented 11 years ago

Crap, just realised this:

1.12345678901234567890.to_json
=> "1.1234567890123457"
andeepak commented 11 years ago

ok I am really glad that you tracked why this is happening, any workaround as of now ?

apneadiving commented 11 years ago

Not yet, I'm digging, angrily wondering why this default behaviour has been implemented...

Seems related to https://github.com/rails/rails/issues/6114

apneadiving commented 11 years ago

Asked on stackoverflow in the meantime: http://stackoverflow.com/questions/13218945/rails-to-json-truncating-floats

apneadiving commented 11 years ago

Two issues were actually not related: I confirm that for this one I'm retrieving results directly from google without rounding myself, so I can't see what I could change.