Skip to content

Commit 845e1a9

Browse files
authored
Fix distance units (firebase#269)
1 parent c051728 commit 845e1a9

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

firestore/app/src/main/java/com/google/example/firestore/SolutionGeoqueries.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,9 @@ public void onComplete(@NonNull Task<List<Task<?>>> t) {
8484
// We have to filter out a few false positives due to GeoHash
8585
// accuracy, but most will match
8686
GeoLocation docLocation = new GeoLocation(lat, lng);
87-
double distance = GeoFireUtils.getDistanceBetween(docLocation, center);
88-
if (distance <= radiusInKm) {
87+
double distanceInM = GeoFireUtils.getDistanceBetween(docLocation, center);
88+
double distanceInKm = distanceInM / 1000;
89+
if (distanceInKm <= radiusInKm) {
8990
matchingDocs.add(doc);
9091
}
9192
}

firestore/app/src/main/java/com/google/example/firestore/kotlin/SolutionGeoqueries.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,9 @@ class SolutionGeoqueries {
6666
// We have to filter out a few false positives due to GeoHash
6767
// accuracy, but most will match
6868
val docLocation = GeoLocation(lat, lng)
69-
val distance = GeoFireUtils.getDistanceBetween(docLocation, center)
70-
if (distance <= radiusInKm) {
69+
val distanceInM = GeoFireUtils.getDistanceBetween(docLocation, center)
70+
val distanceInKm = distanceInM / 1000
71+
if (distanceInKm <= radiusInKm) {
7172
matchingDocs.add(doc)
7273
}
7374
}

0 commit comments

Comments
 (0)