Abhilash
Abhilash

Reputation: 2953

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?

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

Upvotes: 3

Views: 2786

Answers (2)

Hardik Upadhyay
Hardik Upadhyay

Reputation: 2659

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

Upvotes: 2

Dias
Dias

Reputation: 882

Geocoder.coordinates(location)

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

returns [42.700149, -74.922767]

Upvotes: 8

Related Questions