gpt4 book ai didi

ruby - 如何通过 gmaps4rails 对地址进行地理编码并将坐标保存在数组中?

转载 作者:数据小太阳 更新时间:2023-10-29 08:40:26 25 4
gpt4 key购买 nike

我正在使用 gem mongoid_special而不是 mongoid_geo .主要问题是如何使用 gmaps4rails 进行地理编码输入地点并在右侧保存纬度和经度等坐标 mongoid_special数组字段?我预测坐标有很多关联。说明 Material :

/haml view fields (autocompleted with google places)/
= f.text_field :from, :id => 'from'
= f.text_field :waypoints, :id => 'waypoints'
= f.text_field :to, :id => 'from'

class Trip
include Gmaps4rails::ActsAsGmappable
include Mongoid::Document
include Mongoid::Spacial::Document

field :from, :type => String
field :waypoints, type => String
field :to, type => String

field :from_coordinate, type: Array, spacial: {lat: :latitude, lng: :longitude, return_array: true }
field :to_coordinate, type: Array, spacial: {lat: :latitude, lng: :longitude, return_array: true }

embeds_many :coordinates
end

class Coordinates
include Mongoid::Document
include Mongoid::Spacial::Document

field :coordinates, type: Array, spacial: {lat: :latitude, lng: :longitude, return_array: true }

embedded_in :trip
end

进一步的问题是如何从该字段中获取反向地理编码并将数据显示为谷歌方向?

编辑 感谢您提示我针对以下字段的解决方案,其余的我可以以某种方式管理。

before_save :from

def from=(from)
self.from_coordinate = Gmaps4rails.geocode(from).first
end

最佳答案

这是我的建议:

  • 要以您想要的方式获取数据,请创建您自己的before_save 过滤器并使用Gmaps4rails.geocode 方法described here .

  • 要显示方向,see here

  • gmaps4rails 中没有反向地理编码可用

关于ruby - 如何通过 gmaps4rails 对地址进行地理编码并将坐标保存在数组中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8139206/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com