Skip to content
This repository was archived by the owner on Feb 28, 2024. It is now read-only.

Commit de9d649

Browse files
committed
LatLng: fix distanceTo to correctly return meters
1 parent 00f6da1 commit de9d649

File tree

2 files changed

+10
-2
lines changed
  • src
    • main/java/com/sygic/travel/sdk/places/model/geo
    • test/java/com/sygic/travel/sdk/places/model/geo

2 files changed

+10
-2
lines changed

src/main/java/com/sygic/travel/sdk/places/model/geo/LatLng.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ data class LatLng(
2626
val lon2 = point.lng
2727
val p = PI / 180
2828
val a = 0.5 - cos((lat2 - lat1) * p) / 2 + cos(lat1 * p) * cos(lat2 * p) * (1 - cos((lon2 - lon1) * p)) / 2
29-
return 12742 * asin(sqrt(a))
29+
return 12742 * asin(sqrt(a)) * 1000
3030
}
3131

3232
fun withPrecision(decimals: Int = 6): LatLng {

src/test/java/com/sygic/travel/sdk/places/model/geo/LatLngTest.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package com.sygic.travel.sdk.places.model.geo
22

3-
import com.sygic.travel.sdk.places.model.geo.LatLng
43
import org.junit.Assert.assertEquals
54
import org.junit.Test
5+
import kotlin.math.roundToInt
66

77
class LatLngTest {
88
@Test
@@ -24,4 +24,12 @@ class LatLngTest {
2424
latLng.withPrecision(10).toApiExpression()
2525
)
2626
}
27+
28+
@Test
29+
fun testDistance() {
30+
val from = LatLng(49.233461, 16.572517)
31+
val to = LatLng(49.231109, 16.573447)
32+
33+
assertEquals(270, from.distanceTo(to).roundToInt())
34+
}
2735
}

0 commit comments

Comments
 (0)