【问题标题】:Geometry function from lat/long in Hasura not workingHasura中纬度/经度的几何功能不起作用
【发布时间】:2020-07-05 01:31:46
【问题描述】:

我有一张包含位置的表格,包括纬度和经度以及几何列。我想在 Hasura 中使用以下查询计算用户最近的位置:

query {
  near_locations(args: {distance: 30000, lat: 123.123, long: 12.22}) {
    city
  }
}

我使用的函数:

CREATE OR REPLACE FUNCTION public.near_locations(distance integer, lat double precision, long double precision)
 RETURNS SETOF location
 LANGUAGE sql
 STABLE
AS $function$
SELECT * from location
 WHERE ST_DWithin(geolocation, ST_SetSRID(ST_MakePoint(long, lat), 4326), distance)
$function$

当我删除函数中的 lat 和 long 变量并添加静态 lat/long 时,一切似乎都正常...

【问题讨论】:

    标签: postgresql hasura


    【解决方案1】:

    似乎 hasura 对 PostGIG 拓扑运算符具有原生支持。

    所以我最终使用的查询是:

    query nearby_users {
      location(where: {geolocation: {_st_d_within: {distance: 40000, from:  {
            type : "Point", 
            coordinates: [4.895168, 52.370216]
          }}}}) {
        id
        city
      }
    }
    
    

    【讨论】:

      猜你喜欢
      • 2014-12-03
      • 2013-09-29
      • 1970-01-01
      • 2017-01-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-09
      相关资源
      最近更新 更多