Skip to content

Commit b062e74

Browse files
Ehespmikehardy
authored andcommitted
feat: add GeoPoint toJSON() method
1 parent 8fb859f commit b062e74

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

packages/firestore/e2e/GeoPoint.e2e.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,17 @@ describe('firestore.GeoPoint', function () {
106106
equal.should.equal(true);
107107
});
108108
});
109+
110+
describe('toJSON()', function () {
111+
it('returns a json representation of the GeoPoint', function () {
112+
const geo = new firebase.firestore.GeoPoint(100, 200);
113+
geo.toJSON().should.deepEqual({
114+
latitude: 100,
115+
longitude: 200,
116+
});
117+
});
118+
});
119+
109120
it('sets & returns correctly', async function () {
110121
const ref = firebase.firestore().doc(`${COLLECTION}/geopoint`);
111122
await ref.set({

packages/firestore/lib/FirestoreGeoPoint.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,11 @@ export default class FirestoreGeoPoint {
6666

6767
return this._latitude === other._latitude && this._longitude === other._longitude;
6868
}
69+
70+
toJSON() {
71+
return {
72+
latitude: this._latitude,
73+
longitude: this._longitude,
74+
};
75+
}
6976
}

packages/firestore/lib/index.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,11 @@ export namespace FirebaseFirestoreTypes {
808808
* @param other The `GeoPoint` to compare against.
809809
*/
810810
isEqual(other: GeoPoint): boolean;
811+
812+
/**
813+
* Returns a JSON-serializable representation of this GeoPoint.
814+
*/
815+
toJSON(): { latitude: number; longitude: number };
811816
}
812817

813818
/**

0 commit comments

Comments
 (0)