从rails-geocoder gem中的控制器获取纬度和经度值 [英] getting latitude and longitude values from controller in rails-geocoder gem

查看:55
本文介绍了从rails-geocoder gem中的控制器获取纬度和经度值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在rails中使用 geocoder gem时,是否可以在控制器中获取纬度和经度值?

Is it possible to get latitude and longitude values in the controller when using geocoder gem in rails?

当前获取附近所有位置的方法是通过如下所示的位置名称.

What am currently doing for getting all nearby location is pass the location name like below.

event_address = Event.near(location, 15, order: 'distance')

那么,有没有一种方法可以获取上面请求的位置所用的经纬度和经度,以供以后在相同位置的后续请求中使用?

So is there a way to fetch the lat and lng which was used for the above requested location for using later in subsequent requests for same location?

@ latitude =#一些方法

@latitude= #some method

@ longitude = #some_method

@longitude= #some_method

推荐答案

Geocoder.coordinates(location)

例如: Geocoder.coordinates("25 Main St,Cooperstown,NY")

返回[42.700149,-74.922767]

returns [42.700149, -74.922767]

这篇关于从rails-geocoder gem中的控制器获取纬度和经度值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆