-
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.
adds android gmaps extensions, renames internal Location class
- Loading branch information
Showing
15 changed files
with
158 additions
and
91 deletions.
There are no files selected for viewing
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
50 changes: 50 additions & 0 deletions
50
android/src/main/java/com/ivoberger/statikgmapsapi/android/GMapsExtensions.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 |
---|---|---|
@@ -1,2 +1,52 @@ | ||
package com.ivoberger.statikgmapsapi.android | ||
|
||
import android.location.Location | ||
import com.google.android.gms.maps.model.LatLng | ||
import com.google.android.gms.maps.model.Marker | ||
import com.google.android.gms.maps.model.Polyline | ||
import com.google.android.gms.maps.model.PolylineOptions | ||
import com.ivoberger.statikgmapsapi.core.StatikGMapsUrl | ||
import com.ivoberger.statikgmapsapi.core.StatikMapsLocation | ||
|
||
fun Marker.toStatikMapsLocation() = position.toStatikMapsLocation() | ||
fun Location.toStatikMapsLocation() = StatikMapsLocation(latitude, longitude) | ||
fun LatLng.toStatikMapsLocation() = StatikMapsLocation(latitude, longitude) | ||
|
||
fun List<Location>.toPath() = map { StatikMapsLocation(it.latitude, it.longitude) } | ||
|
||
/** | ||
* Sets the path from the points of the given [Polyline] | ||
*/ | ||
fun StatikGMapsUrl.path(polyline: Polyline) = | ||
run { path = polyline.points.map { StatikMapsLocation(it.latitude, it.longitude) } } | ||
|
||
/** | ||
* Sets the path from the points of the given [PolylineOptions] | ||
*/ | ||
fun StatikGMapsUrl.path(polyline: PolylineOptions) = | ||
run { path = polyline.points.map { it.toStatikMapsLocation() } } | ||
|
||
/** | ||
* Sets the path from the points of the given [List] of [LatLng] | ||
*/ | ||
fun StatikGMapsUrl.path(latLngPath: List<LatLng>) = | ||
run { path = latLngPath.map { it.toStatikMapsLocation() } } | ||
|
||
/** | ||
* Adds the given [Marker] to [StatikGMapsUrl.markers] | ||
*/ | ||
fun StatikGMapsUrl.marker(marker: Marker) = marker(marker.position) | ||
|
||
/** | ||
* Adds the given [LatLng] to [StatikGMapsUrl.markers] | ||
*/ | ||
fun StatikGMapsUrl.marker(marker: LatLng) = markers.add(marker.toStatikMapsLocation()) | ||
|
||
/** | ||
* Adds the given [Location] to [StatikGMapsUrl.markers] | ||
*/ | ||
fun StatikGMapsUrl.marker(marker: Location) = markers.add(marker.toStatikMapsLocation()) | ||
|
||
|
||
fun StatikGMapsUrl.visible(latLng: LatLng) = visible.add(latLng.toStatikMapsLocation()) | ||
fun StatikGMapsUrl.visible(location: Location) = visible.add(location.toStatikMapsLocation()) |
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
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
40 changes: 40 additions & 0 deletions
40
core/src/test/kotlin/com/ivoberger/statikgmapsapi/core/Location.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,40 @@ | ||
package com.ivoberger.statikgmapsapi.core | ||
|
||
import io.kotlintest.shouldThrow | ||
import io.kotlintest.specs.StringSpec | ||
|
||
class Location : StringSpec({ | ||
"Should create a valid location" { | ||
for (lat in -90..90) { | ||
for (lng in -180..180) { | ||
StatikMapsLocation(lat.toDouble(), lng.toDouble()) | ||
} | ||
} | ||
StatikMapsLocation(address = "London") | ||
} | ||
"Missing parameters should result in an exception" { | ||
shouldThrow<IllegalArgumentException> { StatikMapsLocation() } | ||
shouldThrow<IllegalArgumentException> { StatikMapsLocation(.0) } | ||
shouldThrow<IllegalArgumentException> { StatikMapsLocation(longitude = .0) } | ||
} | ||
"Providing wrong combinations of parameters should result on an exception" { | ||
shouldThrow<IllegalArgumentException> { StatikMapsLocation(90.0, .0, "London") } | ||
shouldThrow<IllegalArgumentException> { | ||
StatikMapsLocation( | ||
longitude = .0, | ||
address = "London" | ||
) | ||
} | ||
shouldThrow<IllegalArgumentException> { StatikMapsLocation(.0, address = "London") } | ||
} | ||
"Out of range coordinates should result in an exception" { | ||
shouldThrow<IllegalArgumentException> { StatikMapsLocation(91.0, .0) } | ||
shouldThrow<IllegalArgumentException> { StatikMapsLocation(-91.0, .0) } | ||
shouldThrow<IllegalArgumentException> { StatikMapsLocation(.0, 181.0) } | ||
shouldThrow<IllegalArgumentException> { StatikMapsLocation(.0, -181.0) } | ||
} | ||
"A non-null but blank or empty address should result in an exception" { | ||
shouldThrow<IllegalArgumentException> { StatikMapsLocation(address = "") } | ||
shouldThrow<IllegalArgumentException> { StatikMapsLocation(address = " ") } | ||
} | ||
}) |
35 changes: 0 additions & 35 deletions
35
core/src/test/kotlin/com/ivoberger/statikgmapsapi/core/LocationDataClass.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.