diff --git a/spec/ParseGeoPoint.spec.js b/spec/ParseGeoPoint.spec.js index 1dd7710ede..bb23011ecb 100644 --- a/spec/ParseGeoPoint.spec.js +++ b/spec/ParseGeoPoint.spec.js @@ -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); diff --git a/src/Adapters/Storage/Postgres/PostgresStorageAdapter.js b/src/Adapters/Storage/Postgres/PostgresStorageAdapter.js index a01ce25b31..5d61ef7e7b 100644 --- a/src/Adapters/Storage/Postgres/PostgresStorageAdapter.js +++ b/src/Adapters/Storage/Postgres/PostgresStorageAdapter.js @@ -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; } @@ -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})`; }); @@ -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') {