简体   繁体   English

从rails-geocoder gem中的控制器获取纬度和经度值

[英]getting latitude and longitude values from controller in rails-geocoder gem

Is it possible to get latitude and longitude values in the controller when using geocoder gem in rails? 在导轨中使用地理编码器 gem时,是否可以在控制器中获取经度和纬度值?

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= #some method @ latitude =#一些方法

@longitude= #some_method @ longitude = #some_method

Geocoder.coordinates(location)

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

returns [42.700149, -74.922767] 返回[42.700149,-74.922767]

try with Event.geocoded OR 尝试使用Event.geocoded OR

you can use coordinates method of geocoder. 您可以使用地理编码器的coordinates方法。

Ex. 例如

Geocoder.coordinates("Your location goes here") Geocoder.coordinates(“您的位置在这里”)

Its return array containing latitude and longitude 其返回数组包含纬度和经度

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

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