Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

329
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda