-
Notifications
You must be signed in to change notification settings - Fork 0
Add support for location-based filtering #30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
...am-android-core/src/main/java/io/getstream/android/core/api/model/location/BoundingBox.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| /* | ||
| * Copyright (c) 2014-2025 Stream.io Inc. All rights reserved. | ||
| * | ||
| * Licensed under the Stream License; | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://github.com/GetStream/stream-core-android/blob/main/LICENSE | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package io.getstream.android.core.api.model.location | ||
|
|
||
| import io.getstream.android.core.annotations.StreamPublishedApi | ||
|
|
||
| /** | ||
| * A rectangular geographic region defined by northeast and southwest corner coordinates. | ||
| * | ||
| * @param northeast The northeast (top-right) corner coordinate of the bounding box. | ||
| * @param southwest The southwest (bottom-left) corner coordinate of the bounding box. | ||
| */ | ||
| @StreamPublishedApi | ||
| public data class BoundingBox(val northeast: LocationCoordinate, val southwest: LocationCoordinate) | ||
|
|
||
| /** | ||
| * Checks if the specified coordinate is within this bounding box. | ||
| * | ||
| * @param coordinate The coordinate to check. | ||
| * @return True if the coordinate is within the bounding box, false otherwise. | ||
| */ | ||
| internal operator fun BoundingBox.contains(coordinate: LocationCoordinate): Boolean { | ||
| return coordinate.latitude >= southwest.latitude && | ||
| coordinate.latitude <= northeast.latitude && | ||
| coordinate.longitude >= southwest.longitude && | ||
| coordinate.longitude <= northeast.longitude | ||
| } | ||
|
|
||
| /** Converts this bounding box to a map representation suitable for API requests. */ | ||
| internal fun BoundingBox.toRequestMap(): Map<String, Any> = | ||
| mapOf( | ||
| "ne_lat" to northeast.latitude, | ||
| "ne_lng" to northeast.longitude, | ||
| "sw_lat" to southwest.latitude, | ||
| "sw_lng" to southwest.longitude, | ||
| ) |
54 changes: 54 additions & 0 deletions
54
...android-core/src/main/java/io/getstream/android/core/api/model/location/CircularRegion.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| /* | ||
| * Copyright (c) 2014-2025 Stream.io Inc. All rights reserved. | ||
| * | ||
| * Licensed under the Stream License; | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://github.com/GetStream/stream-core-android/blob/main/LICENSE | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package io.getstream.android.core.api.model.location | ||
|
|
||
| import android.location.Location | ||
| import io.getstream.android.core.annotations.StreamPublishedApi | ||
|
|
||
| /** | ||
| * A circular geographic region defined by a center point and a radius. | ||
| * | ||
| * @param center The center coordinate of the circular region. | ||
| * @param radius The radius of the circular region. | ||
| */ | ||
| @StreamPublishedApi | ||
| public data class CircularRegion(val center: LocationCoordinate, val radius: Distance) | ||
|
|
||
| /** | ||
| * Checks if the specified coordinate is within this circular region. | ||
| * | ||
| * @param coordinate The coordinate to check. | ||
| * @return True if the coordinate is within the region, false otherwise. | ||
| */ | ||
| internal operator fun CircularRegion.contains(coordinate: LocationCoordinate): Boolean { | ||
| val centerLocation = | ||
| Location("").apply { | ||
| latitude = this@contains.center.latitude | ||
| longitude = this@contains.center.longitude | ||
| } | ||
| val coordinateLocation = | ||
| Location("").apply { | ||
| latitude = coordinate.latitude | ||
| longitude = coordinate.longitude | ||
| } | ||
| val distance = centerLocation.distanceTo(coordinateLocation).toDouble() | ||
| return distance <= this@contains.radius.inMeters | ||
| } | ||
|
|
||
| /** Converts this circular region to a map representation suitable for API requests. */ | ||
| internal fun CircularRegion.toRequestMap(): Map<String, Any> = | ||
| mapOf("lat" to center.latitude, "lng" to center.longitude, "distance" to radius.inKilometers) |
89 changes: 89 additions & 0 deletions
89
stream-android-core/src/main/java/io/getstream/android/core/api/model/location/Distance.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| /* | ||
| * Copyright (c) 2014-2025 Stream.io Inc. All rights reserved. | ||
| * | ||
| * Licensed under the Stream License; | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://github.com/GetStream/stream-core-android/blob/main/LICENSE | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package io.getstream.android.core.api.model.location | ||
|
|
||
| import io.getstream.android.core.annotations.StreamPublishedApi | ||
|
|
||
| /** | ||
| * Represents a distance measurement with type safety and automatic unit conversion. | ||
| * | ||
| * @param inMeters The distance value stored internally in meters. | ||
| */ | ||
| @JvmInline | ||
| @StreamPublishedApi | ||
| public value class Distance private constructor(public val inMeters: Double) { | ||
|
|
||
| /** Returns the distance value in kilometers. */ | ||
| public val inKilometers: Double | ||
| get() = inMeters / 1000.0 | ||
|
|
||
| internal companion object { | ||
| fun fromMeters(meters: Double): Distance = Distance(meters) | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Extension property to create a [Distance] from a [Double] value in meters. | ||
| * | ||
| * ## Example | ||
| * | ||
| * ```kotlin | ||
| * val distance = 1500.2.meters // 1500.2 meters | ||
| * ``` | ||
| */ | ||
| @StreamPublishedApi | ||
| public val Double.meters: Distance | ||
| get() = Distance.fromMeters(this) | ||
|
|
||
| /** | ||
| * Extension property to create a [Distance] from a [Double] value in kilometers. | ||
| * | ||
| * ## Example | ||
| * | ||
| * ```kotlin | ||
| * val distance = 1.5.kilometers // 1.5 kilometers | ||
| * ``` | ||
| */ | ||
| @StreamPublishedApi | ||
| public val Double.kilometers: Distance | ||
| get() = Distance.fromMeters(this * 1000.0) | ||
|
|
||
| /** | ||
| * Extension property to create a [Distance] from an [Int] value in meters. | ||
| * | ||
| * ## Example | ||
| * | ||
| * ```kotlin | ||
| * val distance = 1500.meters // 1500 meters | ||
| * ``` | ||
| */ | ||
| @StreamPublishedApi | ||
| public val Int.meters: Distance | ||
| get() = toDouble().meters | ||
|
|
||
| /** | ||
| * Extension property to create a [Distance] from an [Int] value in kilometers. | ||
| * | ||
| * ## Example | ||
| * | ||
| * ```kotlin | ||
| * val distance = 5.kilometers // 5 kilometers | ||
| * ``` | ||
| */ | ||
| @StreamPublishedApi | ||
| public val Int.kilometers: Distance | ||
| get() = toDouble().kilometers |
30 changes: 30 additions & 0 deletions
30
...oid-core/src/main/java/io/getstream/android/core/api/model/location/LocationCoordinate.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| /* | ||
| * Copyright (c) 2014-2025 Stream.io Inc. All rights reserved. | ||
| * | ||
| * Licensed under the Stream License; | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://github.com/GetStream/stream-core-android/blob/main/LICENSE | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package io.getstream.android.core.api.model.location | ||
|
|
||
| import io.getstream.android.core.annotations.StreamPublishedApi | ||
|
|
||
| /** | ||
| * Represents a geographic coordinate with latitude and longitude values. | ||
| * | ||
| * This class is used to represent location data in geo-spatial filtering operations. | ||
| * | ||
| * @param latitude The latitude coordinate in degrees. Must be between -90 and 90. | ||
| * @param longitude The longitude coordinate in degrees. Must be between -180 and 180. | ||
| */ | ||
| @StreamPublishedApi | ||
| public data class LocationCoordinate(val latitude: Double, val longitude: Double) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.