Skip to content

Commit

Permalink
can get multiple routes
Browse files Browse the repository at this point in the history
  • Loading branch information
saeedrznr committed Oct 27, 2023
1 parent 6749491 commit 99daa14
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion drawRouteCompose/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ publishing {
register<MavenPublication>("release") {
groupId = "com.github.saeedrznr"
artifactId = "DrawRouteOnMap"
version = "0.0.3"
version = "0.0.4"

afterEvaluate {
from(components["release"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ class ApiService : ViewModel() {
val routes: LiveData<List<List<LatLng>>>
get() = _routes

fun getRoutes(key: String, origin: LatLng, destination: LatLng) {
fun getRoutes(key: String, origin: LatLng, destination: LatLng,alternatives: Boolean) {
val TAG = "drawgooglemaproute-request_response:"
viewModelScope.launch {
try {
val request = Api.invoke().getRoute(
"${origin.latitude},${origin.longitude}",
"${destination.latitude},${destination.longitude}",
key
key,alternatives
)
val data = CoroutineScope(Dispatchers.IO).async {
if (request.isSuccessful) {
Expand Down Expand Up @@ -63,14 +63,14 @@ class ApiService : ViewModel() {
suspend fun getRoute(
@Query("origin") origin: String,
@Query("destination") destination: String,
@Query("key") key: String
@Query("key") key: String,
@Query("alternatives") alternatives:Boolean
): Response<ResponseBody>

companion object {
private val retrofit by lazy {
Retrofit.Builder()
.baseUrl("https://maps.googleapis.com/maps/api/directions/")
//.addConverterFactory(MoshiConverterFactory.create())
.build()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,13 @@ fun DrawRoutes(
originTitle: String = "",
destinationTitle: String = "",
originSnippet: String? = null,
destinationSnippet: String? = null
destinationSnippet: String? = null,
alternatives:Boolean=false
) {
val routesColors = colors ?: listOf(Color.Blue, Color.Red, Color.Green, Color.Magenta)
val apiService: ApiService = viewModel()
val routes by apiService.routes.observeAsState()
apiService.getRoutes(key, origin, destination)
apiService.getRoutes(key, origin, destination,alternatives)
val desMarkerState = rememberMarkerState(position = destination)
val begMarkerState = rememberMarkerState(position = origin)
desMarkerState.showInfoWindow()
Expand Down

0 comments on commit 99daa14

Please sign in to comment.