Мне нужно перечислить все местоположения, которые находятся на указанном расстоянии от моего текущего местоположения. Я создал фиктивную таблицу, координаты которой сохранены как тип данных Point (например, 17.12365, 19.51235). Теперь я хочу выполнить запрос, который вычисляет расстояние между координатой местоположения и моей текущей координатой, и те, чье расстояние меньше 5 км, будут перечислены.
Мой код:
const conditions = {
categoryId: params.categoryId,
};
const latLng = params.longitude + ' ' + params.latitude; // make be may need to reverse
const distance = params.distance ? params.distance : 5;
return getRepository(Location)
.createQueryBuilder()
.select('Location.id', 'id')
.addSelect('Location.coordinate', 'coordinate')
.addSelect('ST_Distance(ST_GeogFromText(\'SRID=4326;POINT(:userLatLng::string)\'), ST_GeogFromText(\'SRID=4326;POINT(Location.coordinate)\'))', 'distance')
.where('"categoryId" = :categoryId', conditions)
.orderBy('distance', 'DESC')
.setParameters({ userLatLng: latLng })
.getMany();
Мой вывод запроса:
message: 'could not determine data type of parameter $1',
name: 'QueryFailedError',
length: 104,
severity: 'ERROR',
code: '42P18',
detail: undefined,
hint: undefined,
position: undefined,
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
constraint: undefined,
file: 'postgres.c',
line: '1371',
routine: 'exec_parse_message',
query: `SELECT "Location"."id" AS "id", "Location"."coordinate" AS "coordinate", ST_Distance(ST_GeogFromText('SRID=4326;POINT($1::string)'), ST_GeogFromText('SRID=4326;POINT("Location"."coordinate")')) AS "distance" FROM "locations" "Location" WHERE "categoryId" = $2 ORDER BY distance DESC`,
parameters: [ '19.290799 73.013336', '1' ]
Пожалуйста, помогите ... !!