How to use the parse/node.GeoPoint function in parse

To help you get started, we’ve selected a few parse examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github parse-community / parse-server / spec / ParseQuery.spec.js View on Github external
it('withJSON supports geoWithin.centerSphere', (done) => {
    const inbound = new Parse.GeoPoint(1.5, 1.5);
    const onbound = new Parse.GeoPoint(10, 10);
    const outbound = new Parse.GeoPoint(20, 20);
    const obj1 = new Parse.Object('TestObject', {location: inbound});
    const obj2 = new Parse.Object('TestObject', {location: onbound});
    const obj3 = new Parse.Object('TestObject', {location: outbound});
    const center = new Parse.GeoPoint(0, 0);
    const distanceInKilometers = 1569 + 1; // 1569km is the approximate distance between {0, 0} and {10, 10}.
    Parse.Object.saveAll([obj1, obj2, obj3]).then(() => {
      const q = new Parse.Query(TestObject);
      const jsonQ = q.toJSON();
      jsonQ.where.location = {
        '$geoWithin': {
          '$centerSphere': [
            center,
            distanceInKilometers / 6371.0
          ]
        }
      };
github parse-community / parse-server / spec / ParseQuery.spec.js View on Github external
it('withJSON supports geoWithin.centerSphere', (done) => {
    const inbound = new Parse.GeoPoint(1.5, 1.5);
    const onbound = new Parse.GeoPoint(10, 10);
    const outbound = new Parse.GeoPoint(20, 20);
    const obj1 = new Parse.Object('TestObject', {location: inbound});
    const obj2 = new Parse.Object('TestObject', {location: onbound});
    const obj3 = new Parse.Object('TestObject', {location: outbound});
    const center = new Parse.GeoPoint(0, 0);
    const distanceInKilometers = 1569 + 1; // 1569km is the approximate distance between {0, 0} and {10, 10}.
    Parse.Object.saveAll([obj1, obj2, obj3]).then(() => {
      const q = new Parse.Query(TestObject);
      const jsonQ = q.toJSON();
      jsonQ.where.location = {
        '$geoWithin': {
          '$centerSphere': [
            center,
            distanceInKilometers / 6371.0
          ]
github parse-community / parse-server / spec / ParseQuery.spec.js View on Github external
it('withJSON supports geoWithin.centerSphere', (done) => {
    const inbound = new Parse.GeoPoint(1.5, 1.5);
    const onbound = new Parse.GeoPoint(10, 10);
    const outbound = new Parse.GeoPoint(20, 20);
    const obj1 = new Parse.Object('TestObject', {location: inbound});
    const obj2 = new Parse.Object('TestObject', {location: onbound});
    const obj3 = new Parse.Object('TestObject', {location: outbound});
    const center = new Parse.GeoPoint(0, 0);
    const distanceInKilometers = 1569 + 1; // 1569km is the approximate distance between {0, 0} and {10, 10}.
    Parse.Object.saveAll([obj1, obj2, obj3]).then(() => {
      const q = new Parse.Query(TestObject);
      const jsonQ = q.toJSON();
      jsonQ.where.location = {
        '$geoWithin': {
          '$centerSphere': [
            center,
            distanceInKilometers / 6371.0
          ]
        }
github parse-community / parse-server / src / Adapters / Storage / Postgres / PostgresStorageAdapter.js View on Github external
values.push(fieldName, `((${left}, ${bottom}), (${right}, ${top}))`);
      index += 2;
    }

    if (fieldValue.$geoWithin && fieldValue.$geoWithin.$centerSphere) {
      const centerSphere = fieldValue.$geoWithin.$centerSphere;
      if (!(centerSphere instanceof Array) || centerSphere.length < 2) {
        throw new Parse.Error(
          Parse.Error.INVALID_JSON,
          'bad $geoWithin value; $centerSphere should be an array of Parse.GeoPoint and distance'
        );
      }
      // Get point, convert to geo point if necessary and validate
      let point = centerSphere[0];
      if (point instanceof Array && point.length === 2) {
        point = new Parse.GeoPoint(point[1], point[0]);
      } else if (!GeoPointCoder.isValidJSON(point)) {
        throw new Parse.Error(
          Parse.Error.INVALID_JSON,
          'bad $geoWithin value; $centerSphere geo point invalid'
        );
      }
      Parse.GeoPoint._validate(point.latitude, point.longitude);
      // Get distance and validate
      const distance = centerSphere[1];
      if (isNaN(distance) || distance < 0) {
        throw new Parse.Error(
          Parse.Error.INVALID_JSON,
          'bad $geoWithin value; $centerSphere distance invalid'
        );
      }
      const distanceInKM = distance * 6371 * 1000;
github parse-community / parse-server / spec / QueryTools.spec.js View on Github external
expect(matchesQuery(santaClara, q)).toBe(false);
    expect(matchesQuery(noLocation, q)).toBe(false);
    expect(matchesQuery(nullLocation, q)).toBe(false);
    // Invalid rectangles
    q = new Parse.Query('Checkin').withinGeoBox(
      'location',
      new Parse.GeoPoint(37.822802, -122.373962),
      new Parse.GeoPoint(37.708813, -122.526398)
    );

    expect(matchesQuery(caltrainStation, q)).toBe(false);
    expect(matchesQuery(santaClara, q)).toBe(false);

    q = new Parse.Query('Checkin').withinGeoBox(
      'location',
      new Parse.GeoPoint(37.708813, -122.373962),
      new Parse.GeoPoint(37.822802, -122.526398)
    );

    expect(matchesQuery(caltrainStation, q)).toBe(false);
    expect(matchesQuery(santaClara, q)).toBe(false);
  });
github parse-community / parse-server / spec / QueryTools.spec.js View on Github external
};

    let q = new Parse.Query('Checkin').withinGeoBox(
      'location',
      new Parse.GeoPoint(37.708813, -122.526398),
      new Parse.GeoPoint(37.822802, -122.373962)
    );

    expect(matchesQuery(caltrainStation, q)).toBe(true);
    expect(matchesQuery(santaClara, q)).toBe(false);
    expect(matchesQuery(noLocation, q)).toBe(false);
    expect(matchesQuery(nullLocation, q)).toBe(false);
    // Invalid rectangles
    q = new Parse.Query('Checkin').withinGeoBox(
      'location',
      new Parse.GeoPoint(37.822802, -122.373962),
      new Parse.GeoPoint(37.708813, -122.526398)
    );

    expect(matchesQuery(caltrainStation, q)).toBe(false);
    expect(matchesQuery(santaClara, q)).toBe(false);

    q = new Parse.Query('Checkin').withinGeoBox(
      'location',
      new Parse.GeoPoint(37.708813, -122.373962),
      new Parse.GeoPoint(37.822802, -122.526398)
    );

    expect(matchesQuery(caltrainStation, q)).toBe(false);
    expect(matchesQuery(santaClara, q)).toBe(false);
  });
github parse-community / parse-server / spec / QueryTools.spec.js View on Github external
let q = new Parse.Query('Checkin').withinGeoBox(
      'location',
      new Parse.GeoPoint(37.708813, -122.526398),
      new Parse.GeoPoint(37.822802, -122.373962)
    );

    expect(matchesQuery(caltrainStation, q)).toBe(true);
    expect(matchesQuery(santaClara, q)).toBe(false);
    expect(matchesQuery(noLocation, q)).toBe(false);
    expect(matchesQuery(nullLocation, q)).toBe(false);
    // Invalid rectangles
    q = new Parse.Query('Checkin').withinGeoBox(
      'location',
      new Parse.GeoPoint(37.822802, -122.373962),
      new Parse.GeoPoint(37.708813, -122.526398)
    );

    expect(matchesQuery(caltrainStation, q)).toBe(false);
    expect(matchesQuery(santaClara, q)).toBe(false);

    q = new Parse.Query('Checkin').withinGeoBox(
      'location',
      new Parse.GeoPoint(37.708813, -122.373962),
      new Parse.GeoPoint(37.822802, -122.526398)
    );

    expect(matchesQuery(caltrainStation, q)).toBe(false);
    expect(matchesQuery(santaClara, q)).toBe(false);
  });
github parse-community / parse-server / spec / QueryTools.spec.js View on Github external
it('matches on equality queries', function() {
    const day = new Date();
    const location = new Parse.GeoPoint({
      latitude: 37.484815,
      longitude: -122.148377,
    });
    const obj = {
      id: new Id('Person', 'O1'),
      score: 12,
      name: 'Bill',
      birthday: day,
      lastLocation: location,
    };

    let q = new Parse.Query('Person');
    q.equalTo('score', 12);
    expect(matchesQuery(obj, q)).toBe(true);

    q = new Parse.Query('Person');
github parse-community / parse-server / spec / QueryTools.spec.js View on Github external
it('matches $within queries', function() {
    const caltrainStation = {
      id: new Id('Checkin', 'C1'),
      location: new Parse.GeoPoint(37.776346, -122.394218),
      name: 'Caltrain',
    };

    const santaClara = {
      id: new Id('Checkin', 'C2'),
      location: new Parse.GeoPoint(37.325635, -121.945753),
      name: 'Santa Clara',
    };

    const noLocation = {
      id: new Id('Checkin', 'C2'),
      name: 'Santa Clara',
    };

    const nullLocation = {
      id: new Id('Checkin', 'C2'),
github parse-community / parse-server / spec / QueryTools.spec.js View on Github external
id: new Id('Checkin', 'C1'),
    };
    const ptNull = {
      id: new Id('Checkin', 'C1'),
      location: null,
    };
    expect(matchesQuery(pt, q)).toBe(true);
    expect(matchesQuery(ptUndefined, q)).toBe(false);
    expect(matchesQuery(ptNull, q)).toBe(false);

    q = new Parse.Query('Checkin');
    pt.location = new Parse.GeoPoint(40, 40);
    q.withinRadians('location', new Parse.GeoPoint(30, 30), 0.3);
    expect(matchesQuery(pt, q)).toBe(true);

    q.withinRadians('location', new Parse.GeoPoint(30, 30), 0.2);
    expect(matchesQuery(pt, q)).toBe(false);
  });