diff --git a/spec/ParseGeoPoint.spec.js b/spec/ParseGeoPoint.spec.js index aeae2034a1..109939c58f 100644 --- a/spec/ParseGeoPoint.spec.js +++ b/spec/ParseGeoPoint.spec.js @@ -53,7 +53,6 @@ describe('Parse.GeoPoint testing', () => { obj.set('name', 'Zhoul') obj.save(null, { success: (obj) => { - console.log(obj); Parse.Cloud.httpRequest({ url: 'http://localhost:8378/1/classes/TestObject/' + obj.id, headers: { @@ -316,6 +315,21 @@ describe('Parse.GeoPoint testing', () => { }); }); + 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('works with geobox queries', (done) => { var inSF = new Parse.GeoPoint(37.75, -122.4); var southwestOfSF = new Parse.GeoPoint(37.708813, -122.526398); @@ -376,6 +390,23 @@ describe('Parse.GeoPoint testing', () => { }); }); + it('equalTo geopoint', (done) => { + var point = new Parse.GeoPoint(44.0, -11.0); + var obj = new TestObject(); + obj.set('location', point); + obj.save().then(() => { + const query = new Parse.Query(TestObject); + query.equalTo('location', point); + return query.find(); + }).then((results) => { + equal(results.length, 1); + const loc = results[0].get('location'); + equal(loc.latitude, point.latitude); + equal(loc.longitude, point.longitude); + done(); + }); + }); + it('supports withinPolygon', (done) => { const point1 = new Parse.GeoPoint(1.5, 1.5); const point2 = new Parse.GeoPoint(2, 8); diff --git a/src/Adapters/Storage/Postgres/PostgresStorageAdapter.js b/src/Adapters/Storage/Postgres/PostgresStorageAdapter.js index 557ba78a00..55df59c4f6 100644 --- a/src/Adapters/Storage/Postgres/PostgresStorageAdapter.js +++ b/src/Adapters/Storage/Postgres/PostgresStorageAdapter.js @@ -401,6 +401,12 @@ const buildWhereClause = ({ schema, query, index }) => { index += 2; } + if (fieldValue.__type === 'GeoPoint') { + patterns.push('$' + index + ':name ~= POINT($' + (index + 1) + ', $' + (index + 2) + ')'); + values.push(fieldName, fieldValue.longitude, fieldValue.latitude); + index += 3; + } + Object.keys(ParseToPosgresComparator).forEach(cmp => { if (fieldValue[cmp]) { const pgComparator = ParseToPosgresComparator[cmp];