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

to_gmaps4rails and custom lat and lng column names #234

Closed lightalloy closed 12 years ago

lightalloy commented 12 years ago

No results for to_gmaps4rails, when custom :lat_column and :lng_column are given.

If I have this code in model

acts_as_gmappable :lat => "g_latitude", :lng => "g_longitude"

to_gmaps4rails always returns empty result

1.8.7 :011 > c.to_gmaps4rails
 => "[]" 

When I have just

acts_as_gmappable

it works

1.8.7 :018 > c.to_gmaps4rails
 => "[{\"lng\":14.4251733,\"lat\":50.0787104}]" 

Before testing latitude, longitude, g_latitude and g_longitude columns were nil.

I believe it's because of this code in json_builder.rb

    def compliant?
      !(@object.send(@object.gmaps4rails_options[:lat_column]).blank? && @object.send(@object.gmaps4rails_options[:lng_column]).blank?)
    end

@object.gmaps4rails_options[:lat_column]) and @object.gmaps4rails_options[:lng_column]) are blank, cause object hasn't been geocoded yet, but it still should be geocoded, when we call to_gmaps4rails, isn't it?

apneadiving commented 12 years ago

No it's not geocoded when you run to_gmaps4rails.

It's geocoded on save with custom options explained in the wiki.

Custom lat/lng name specs pass so I'm confident in this feature.

Sent from my iPhone

On 11 juil. 2012, at 11:26, Anna Buyanovareply@reply.github.com wrote:

No results for to_gmaps4rails, when custom :lat_column and :lng_column are given.

If I have this code in model

acts_as_gmappable :lat => "g_latitude", :lng => "g_longitude"

to_gmaps4rails always returns empty result

1.8.7 :011 > c.to_gmaps4rails
=> "[]" 

When I have just

acts_as_gmappable

it works

1.8.7 :018 > c.to_gmaps4rails
=> "[{\"lng\":14.4251733,\"lat\":50.0787104}]" 

Before testing latitude, longitude, g_latitude and g_longitude columns were nil.

I believe it's because of this code in json_builder.rb

   def compliant?
     !(@object.send(@object.gmaps4rails_options[:lat_column]).blank? && @object.send(@object.gmaps4rails_options[:lng_column]).blank?)
   end

@object.gmaps4rails_options[:lat_column]) and @object.gmaps4rails_options[:lng_column]) are blank, cause object hasn't been geocoded yet, but it still should be geocoded, when we call to_gmaps4rails, isn't it?


Reply to this email directly or view it on GitHub: https://github.com/apneadiving/Google-Maps-for-Rails/issues/234