Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

257
Visualizações
ST_MakeEnvelope with Google Maps Coordinates problem

In postgress I have the following function that uses ST_MakeEnvelope based on the Google Maps viewport coordinates to returns all projects within that viewport.

CREATE OR REPLACE FUNCTION public.search_projects_area(
  lngw double precision,
  lats double precision,
  lnge double precision,
  latn double precision
) RETURNS SETOF project_locations LANGUAGE sql STABLE AS $ function $
SELECT
  A.*
FROM
  project_locations A
WHERE
  st_intersects(
    A.location :: geography,
    ST_MakeEnvelope(lngw, lats, lnge, latn, 4326) :: geography
  ) $ function $

Below is how I get the coordinates to create the envelope:

const bounds = this.map.getBounds();
const sw = this.map.getBounds().getSouthWest();
const ne = this.map.getBounds().getNorthEast();
const lngw = sw.lng();
const lats = sw.lat();
const lnge = ne.lng();
const latn = ne.lat();

The problem is that projects in specific areas are not fetched sometimes depending on where I have the map zoomed or positioned. The projects are defenitely inside the viewport though in all cases.

Its as if the ST_MakeEnvelope method doesnt create the correct rectangle based on the map viewport.

Is my code above correct?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

By casting to geography, the bounding box edges are created using great circle arcs instead of straight lines. Therefore, a point that looks inside the viewport (projected in 3857) may be outside of the box.

So either you do want to work with great circle arcs and it is a display issue, or you want to stick to what is displayed and you would need to remove the cast to geography

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda