【问题标题】:get the location list based on the current location of the end user with gocoder使用gocoder根据终端用户的当前位置获取位置列表
【发布时间】:2014-07-19 09:27:15
【问题描述】:

我正在尝试查找离最终用户和字符串最近的位置

目前使用 geocoder gem,如下方式

locations = Geocoder.search(search_location)

目前它为我提供了与 search_location 匹配的位置..

我想要的如下......

给出当前用户的经纬度,根据search_location找到最近的位置。

下面我已经试过了

locations = Location.near([current_user.latitude, current_user.longitude], 50, :order => :distance)

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-3 geolocation rails-geocoder


    【解决方案1】:

    Geocoder有一个定位方法可以用来获取用户的ip地址:

    @userLocation = request.location #gets the ip of the user
    @searchResults = Geocoder.search(search_locations)
    @locations = @searchResults.near(@userLocation, 50, :order => :distance)
    

    【讨论】:

    • 什么是search_locations
    猜你喜欢
    • 2011-07-20
    • 2023-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多