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

328
Visualizações
Typeorm Postgis order by nearest Point

I have a postgis database with a bunch of points and I would like to get the points in order of the distance to my own position (longitude and latitude).

So I want to do something like:

const markers = await this.markerRepo.find({
  where: {
    type: "test"
  },
  order: { position: 'ASC' },
});

But I want to order them in relation to my current position.

This id my table entity (Nestjs):

@Entity()
 export class Marker {
   @PrimaryGeneratedColumn()
   id: number;

   @Column({
     type: 'geography',
     spatialFeatureType: 'Point',
     srid: 4326,
     nullable: true,
   })
   position: Point;
 
   @Column()
   type: string;
 }

If you need any more information please let me know

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Turns out Typeorm does not support Postgis (Who would have thought)

The solution is to just send a SQL request like this:

const markers = await this.markerRepo.query(
  `SELECT * , ST_Distance(ST_MakePoint(${yourLatitude}, ${yourLongitude} ), position) AS dist FROM marker ORDER BY dist LIMIT 10;`,
);
about 4 years ago · Juan Pablo Isaza 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