|
1 | 1 | package com.ckdroid.geofirequery.utils
|
2 | 2 |
|
3 | 3 | import com.ckdroid.geofirequery.model.BoundingBox
|
| 4 | +import com.ckdroid.geofirequery.model.Bounds |
4 | 5 | import com.ckdroid.geofirequery.model.QueryLocation
|
5 | 6 | import com.google.firebase.firestore.GeoPoint
|
6 | 7 | import kotlin.math.*
|
@@ -60,34 +61,23 @@ class BoundingBoxUtils(private val distanceUnit: DistanceUnit) {
|
60 | 61 | return BoundingBox(minimumLatitude, minimumLongitude, maximumLatitude, maximumLongitude)
|
61 | 62 | }
|
62 | 63 |
|
63 |
| - fun getBoundingBoxForNew(queryLocation: QueryLocation, distance: Double): BoundingBox { |
| 64 | + fun getBoundingBoxForNew(queryLocation: QueryLocation, distance: Double): Bounds { |
64 | 65 | val nearByLocationList: MutableList<GeoPoint> = mutableListOf()
|
65 | 66 |
|
66 | 67 | (1..200).forEach { _ ->
|
67 | 68 | nearByLocationList.add(pointAtDistance(queryLocation, distance))
|
68 | 69 | }
|
69 | 70 |
|
70 |
| - if (nearByLocationList.isNotEmpty()) { |
71 |
| - val sortedBounds = nearByLocationList.sortedWith(compareBy({ it.latitude }, { it.longitude })) |
| 71 | + val boundList: MutableList<Double> = mutableListOf() |
72 | 72 |
|
73 |
| - val minimumGeoPoint = sortedBounds.first() |
74 |
| - |
75 |
| - val maximumGeoPoint = sortedBounds.last() |
76 |
| - |
77 |
| - return BoundingBox( |
78 |
| - minimumGeoPoint.latitude, |
79 |
| - minimumGeoPoint.longitude, |
80 |
| - maximumGeoPoint.latitude, |
81 |
| - maximumGeoPoint.longitude |
82 |
| - ) |
| 73 | + for (geoPoint in nearByLocationList) { |
| 74 | + val bound = (geoPoint.latitude + 90) * 180 + geoPoint.longitude |
| 75 | + boundList.add(bound) |
83 | 76 | }
|
84 | 77 |
|
85 |
| - return BoundingBox( |
86 |
| - queryLocation.latitude, |
87 |
| - queryLocation.longitude, |
88 |
| - queryLocation.latitude, |
89 |
| - queryLocation.longitude |
90 |
| - ) |
| 78 | + val sortedBoundList = boundList.sortedBy { it } |
| 79 | + |
| 80 | + return Bounds(sortedBoundList.first(), sortedBoundList.last()) |
91 | 81 | }
|
92 | 82 |
|
93 | 83 | private fun pointAtDistance(queryLocation: QueryLocation, distance: Double): GeoPoint {
|
|
0 commit comments