Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions spec/ParseGeoPoint.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,21 @@ describe('Parse.GeoPoint testing', () => {
Parse.Object.saveAll([sacramento, sf, honolulu], callback);
};

it('returns nearest location', (done) => {
makeSomeGeoPoints(function() {
var sfo = new Parse.GeoPoint(37.6189722, -122.3748889);
var query = new Parse.Query(TestObject);
query.near('location', sfo);
query.find({
success: function(results) {
equal(results[0].get('name'), 'San Francisco');
equal(results[1].get('name'), 'Sacramento');
done();
}
});
});
});

it('geo max distance in km everywhere', (done) => {
makeSomeGeoPoints(function() {
var sfo = new Parse.GeoPoint(37.6189722, -122.3748889);
Expand Down
14 changes: 7 additions & 7 deletions src/Adapters/Storage/Postgres/PostgresStorageAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,19 +328,19 @@ const buildWhereClause = ({ schema, query, index }) => {
const distanceInKM = distance * 6371 * 1000;
patterns.push(`ST_distance_sphere($${index}:name::geometry, POINT($${index + 1}, $${index + 2})::geometry) <= $${index + 3}`);
sorts.push(`ST_distance_sphere($${index}:name::geometry, POINT($${index + 1}, $${index + 2})::geometry) ASC`)
values.push(fieldName, point.longitude, point.latitude, distanceInKM);
values.push(fieldName, point.latitude, point.longitude, distanceInKM);
index += 4;
}

if (fieldValue.$within && fieldValue.$within.$box) {
const box = fieldValue.$within.$box;
const left = box[0].longitude;
const bottom = box[0].latitude;
const right = box[1].longitude;
const left = box[0].longitude;
const top = box[1].latitude;
const right = box[1].longitude;

patterns.push(`$${index}:name::point <@ $${index + 1}::box`);
values.push(fieldName, `((${left}, ${bottom}), (${right}, ${top}))`);
values.push(fieldName, `((${bottom}, ${left}), (${top}, ${right}))`);
index += 2;
}

Expand Down Expand Up @@ -767,7 +767,7 @@ export class PostgresStorageAdapter {
});
const geoPointsInjects = Object.keys(geoPoints).map((key) => {
const value = geoPoints[key];
valuesArray.push(value.longitude, value.latitude);
valuesArray.push(value.latitude, value.longitude);
const l = valuesArray.length + columnsArray.length;
return `POINT($${l}, $${l + 1})`;
});
Expand Down Expand Up @@ -1078,8 +1078,8 @@ export class PostgresStorageAdapter {
if (object[fieldName] && schema.fields[fieldName].type === 'GeoPoint') {
object[fieldName] = {
__type: "GeoPoint",
latitude: object[fieldName].y,
longitude: object[fieldName].x
latitude: object[fieldName].x,
longitude: object[fieldName].y
}
}
if (object[fieldName] && schema.fields[fieldName].type === 'File') {
Expand Down