-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
200 additions
and
55 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
app/src/main/java/com/nqmgaming/searchaddresslab/core/util/CalculateDistance.kt
This file contains 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,29 @@ | ||
package com.nqmgaming.searchaddresslab.core.util | ||
|
||
import kotlin.math.atan2 | ||
import kotlin.math.cos | ||
import kotlin.math.pow | ||
import kotlin.math.sin | ||
import kotlin.math.sqrt | ||
|
||
object CalculateDistance { | ||
fun calculateDistance( | ||
lat1: Double, | ||
lon1: Double, | ||
lat2: Double, | ||
lon2: Double | ||
): Double { | ||
val earthRadius = 6371.0 // radius of the earth in kilometers | ||
|
||
val latDistance = Math.toRadians(lat2 - lat1) | ||
val lonDistance = Math.toRadians(lon2 - lon1) | ||
|
||
val a = sin(latDistance / 2).pow(2.0) + | ||
cos(Math.toRadians(lat1)) * cos(Math.toRadians(lat2)) * | ||
sin(lonDistance / 2).pow(2.0) | ||
|
||
val c = 2 * atan2(sqrt(a), sqrt(1 - a)) | ||
|
||
return earthRadius * c | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
|
@@ -7,4 +7,5 @@ data class Item( | |
val mapView: MapView?, | ||
val position: Position?, | ||
val title: String?, | ||
var distance: Double?, | ||
) |
This file contains 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
This file contains 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
This file contains 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.