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

帅比萌擦擦* 提交于 2020-01-03 03:01:14

问题


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= #some method

@longitude= #some_method


回答1:


Geocoder.coordinates(location)

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

returns [42.700149, -74.922767]




回答2:


try with Event.geocoded OR

you can use coordinates method of geocoder.

Ex.

Geocoder.coordinates("Your location goes here")

Its return array containing latitude and longitude



来源:https://stackoverflow.com/questions/38075452/getting-latitude-and-longitude-values-from-controller-in-rails-geocoder-gem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!