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

时间:2016-06-28 11:50:07

标签: ruby-on-rails ruby google-maps rails-geocoder

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

目前为获取附近所有位置所做的工作是通过下面的位置名称。

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

那么有没有办法获取用于上述请求位置的lat和lng,以便稍后在相同位置的后续请求中使用?

@ latitude = #some method

@longitude = #some_method

2 个答案:

答案 0 :(得分:6)

var vow = "Night gathers, and now my watch begins. It shall not end until my death. I shall take no wife, hold no lands, father no children. I shall wear no crowns and win no glory. I shall live and die at my post. I am the sword in the darkness. I am the watcher on the walls. I am the shield that guards the realms of men. I pledge my life and honor to the Night's Watch, for this night and all the nights to come.";

var wordsToBold=["night","watcher"];

function makeBold(input, wordsToBold) {
return input.replace(new RegExp('(\\b)(' + wordsToBold.join('|') + ')(\\b)','ig'), '$1<b>$2</b>$3');
}

document.getElementById("vow_p").innerHTML = makeBold(vow, wordsToBold);

例如:Geocoder.coordinates(location)

返回[42.700149,-74.922767]

答案 1 :(得分:2)

尝试使用Event.geocoded

您可以使用coordinates地理编码器方法。

实施例

  

Geocoder.coordinates(“您的位置在这里”)

包含纬度和经度的返回数组