1
votes

I am using the geocoder gem for the first time in my rails app. My question is little generic. My rails app need to submit from and to address. When I look at the documentation provided in the github page, we have something like

rails generate migration AddLatitudeAndLongitudeToModel latitude:float longitude:float
rake db:migrate

Say supposing, my model name is Location which has two address fields: from_address and to_address then should I have latitudes and longitudes separately for from and to address? if I set geo_code to both of these from and to addresses. i.e., something like

In my Location model

geocoded_by :from_address,:to_address

And,

Model : Location

Location(from_address: string, to_address:string, from_address_latitude: float, to_address_longitude: float, to_address_latitude: float, to_address_longitude: float)

So in short, should I have a separate latitude and longitude fields for both of these address fields(i.e., from_address and to_address) or is it simply enough to have just latitude and longitude?

1

1 Answers

0
votes

You should define latitude and longitude for both addresses, then the following should work:

geocoded_by :from_address,
  latitude: :from_address_latitude,
  longitude: :from_address_longitude

geocoded_by :to_address,
  latitude: :to_address_latitude,
  longitude: :to_address_longitude