繁体   English   中英

地理编码器宝石导轨中的多个坐标

[英]Multiple Coordinates in geocoder gem rails

我是在Rails应用中第一次使用geocoder gem。 我的问题很少。 我的Rails应用程序需要从和提交地址。 当我查看github页面中提供的文档时,我们会看到类似

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

假设,我的模型名称是Location ,它具有两个地址字段from_addressto_address,那么我应该分别为from和to分配纬度和经度吗? 如果我将geo_code都设置为from和to地址。 即,像

在我的位置模型中

geocoded_by :from_address,:to_address

和,

型号:位置

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

简而言之,对于这两个地址字段(ie, from_address and to_address) ,我是否应该有一个单独的纬度和经度字段?或者仅仅具有纬度和经度就足够了吗?

您应该为这两个地址定义经度和纬度,然后应能进行以下操作:

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM