我正在使用地理编码器。我想靠近位置,但它返回一个空数组。
在数据库中得到这个:
"id": 5,
"name": "sogra2",
"lat": "-22.833575",
"long": "-43.312882",
这是我使用近坐标的动作
def near
@near = Test.near([-22.844279, -43.306174], 100, :units => :km)
render json: @near
end
这是我的模型:
class Test < ApplicationRecord
reverse_geocoded_by :lat, :long
end
发布查询
SELECT tests.*, (111.19492664455873 * ABS(tests.lat - -22.844279) *
0.7071067811865475) + (96.29763124613503 * ABS(tests.long - -43.306174) * 0.7071067811865475) AS distance, CASE WHEN (tests.lat >= -22.844279 AND tests.long >= -43.306174) THEN 45.0 WHEN (tests.lat < -22.844279 AND tests.long >= -43.306174) THEN 135.0 WHEN (tests.lat < -22.844279 AND tests.long < -43.306174) THEN 225.0 WHEN (tests.lat >= -22.844279 AND tests.long < -43.306174) THEN 315.0 END AS bearing FROM "tests" WHERE (tests.lat BETWEEN -23.74360060591873 AND
-21.94495739408127 AND tests.long BETWEEN -44.282039151718706 AND -42.33030884828129) ORDER BY distance ASC
它回来了[]
Rails 5.1 API 模式