'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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
