最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

kotlin - I'm trying to add Map SDK navigation but using jetpack compose, any ideas that can help me? - Stack Overflow

programmeradmin0浏览0评论

The idea is to create the route to the location directly from the app, without having to use the internal app. Previously, I used the Route API and created the route and updated it. But I've checked and now you can use the navigation SDK more directly. I'm asking if anyone has used it and I'm trying to see if I can implement it using Jetpack Compose.

dependencies {
implementation (".jetbrains.kotlin:kotlin-stdlib:2.0.21")
implementation("androidx.core:core-ktx:1.15.0")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.8.7")
implementation("androidx.activity:activity-compose:1.9.3")
implementation(platform("androidxpose:compose-bom:2023.10.01"))
implementation("androidxpose.ui:ui:1.7.6")
implementation("androidxpose.ui:ui-graphics")
implementation("androidxpose.ui:ui-tooling-preview:1.7.6")
implementation("androidxpose.material3:material3:1.4.0-alpha05")
implementation("androidxpose.material:material:1.7.6")
//kapt ("androidxposepiler:compiler:2.0.0")

testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.2.1")
androidTestImplementation("androidx.test.espresso:espresso-core:3.6.1")
androidTestImplementation(platform("androidxpose:compose-bom:2023.10.01"))
androidTestImplementation("androidxpose.ui:ui-test-junit4")

implementation ("androidx.appcompat:appcompat:1.7.0")
implementation ("androidx.navigation:navigation-compose:2.8.5")
implementation ("androidx.constraintlayout:constraintlayout-compose:1.1.0")
implementation("androidxpose.material:material-icons-core:1.7.6")
implementation( "androidxpose.material:material-icons-extended:1.7.6")
implementation("androidxpose.material:material:1.8.0-alpha07")
implementation("androidxpose.animation:animation:1.8.0-alpha07")

implementation ("androidxpose.foundation:foundation:1.7.6")
implementation ("com.google.accompanist:accompanist-permissions:0.33.2-alpha")
implementation ("com.google.accompanist:accompanist-pager:0.33.2-alpha")
implementation ("io.coil-kt:coil-compose:2.5.0")
implementation("com.google.accompanist:accompanist-pager-indicators:0.33.2-alpha")
implementation("com.google.accompanist:accompanist-systemuicontroller:0.33.2-alpha")
implementation("com.flaviofaria:kenburnsview:1.0.7")
implementation ("androidx.core:core-splashscreen:1.0.1")
//implementation ("com.github.togisoft:jetpack_compose_country_code_picker:1.1.4")
implementation ("com.googlecode.libphonenumber:libphonenumber:8.13.52")
//implementation("com.github.togisoft:ccp:1.")

implementation(platform("com.google.firebase:firebase-bom:32.6.0"))
implementation("com.google.firebase:firebase-analytics")
//implementation("com.google.firebase:firebase-auth-ktx")
implementation("com.google.firebase:firebase-messaging-ktx")

// [START gradle_firebase_ui_auth]
implementation("com.firebaseui:firebase-ui-auth:8.0.2")

implementation("com.jakewharton.timber:timber:5.0.1")
implementation("androidxpose.animation:animation-graphics")
implementation("androidx.media3:media3-exoplayer:1.5.1")
//ui
implementation("androidx.media3:media3-ui:1.5.1")

//maps
implementation("com.google.android.gms:play-services-auth:21.3.0")
implementation("com.google.android.gms:play-services-auth-api-phone:18.1.0")
implementation ("com.google.android.libraries.maps:maps:3.1.0-beta")

implementation ("com.google.android.gms:play-services-location:21.3.0")
implementation("com.google.maps.android:maps-compose:6.4.0")
implementation("com.google.android.gms:play-services-maps:19.1.0")
implementation("com.google.maps.android:android-maps-utils:2.3.0")


implementation("com.google.android.libraries.places:places:4.1.0")
implementation ("com.google.dagger:hilt-android:2.51.1")
implementation ("androidx.lifecycle:lifecycle-viewmodel-ktx:2.8.7")
implementation ("androidx.lifecycle:lifecycle-runtime-compose:2.8.7")
kapt("com.google.dagger:hilt-compiler:2.51.1")

implementation ("com.android.volley:volley:1.2.1")

implementation ("com.google.code.gson:gson:2.10.1")
implementation ("com.githubposeuisuite:ohteepee:1.0.3")
implementation ("com.github.Muratthekus:Compose-CurrencyText:1.0")

implementation ("com.google.api-client:google-api-client:2.0.0")

implementation("com.google.auth:google-auth-library-oauth2-http:1.19.0")
implementation ("com.squareup.retrofit2:retrofit:2.11.0")
implementation ("com.squareup.retrofit2:converter-gson:2.11.0")
implementation("com.karumi:dexter:6.2.3")
implementation ("androidx.work:work-runtime-ktx:2.10.0")
implementation(".greenrobot:eventbus:3.3.1")
implementation ("com.github.bumptech.glide:compose:1.0.0-alpha.1")
implementation ("com.github.DogusTeknoloji:compose-date-picker:1.1.0")

The idea is to create the route to the location directly from the app, without having to use the internal app. Previously, I used the Route API and created the route and updated it. But I've checked and now you can use the navigation SDK more directly. I'm asking if anyone has used it and I'm trying to see if I can implement it using Jetpack Compose.

dependencies {
implementation (".jetbrains.kotlin:kotlin-stdlib:2.0.21")
implementation("androidx.core:core-ktx:1.15.0")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.8.7")
implementation("androidx.activity:activity-compose:1.9.3")
implementation(platform("androidxpose:compose-bom:2023.10.01"))
implementation("androidxpose.ui:ui:1.7.6")
implementation("androidxpose.ui:ui-graphics")
implementation("androidxpose.ui:ui-tooling-preview:1.7.6")
implementation("androidxpose.material3:material3:1.4.0-alpha05")
implementation("androidxpose.material:material:1.7.6")
//kapt ("androidxposepiler:compiler:2.0.0")

testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.2.1")
androidTestImplementation("androidx.test.espresso:espresso-core:3.6.1")
androidTestImplementation(platform("androidxpose:compose-bom:2023.10.01"))
androidTestImplementation("androidxpose.ui:ui-test-junit4")

implementation ("androidx.appcompat:appcompat:1.7.0")
implementation ("androidx.navigation:navigation-compose:2.8.5")
implementation ("androidx.constraintlayout:constraintlayout-compose:1.1.0")
implementation("androidxpose.material:material-icons-core:1.7.6")
implementation( "androidxpose.material:material-icons-extended:1.7.6")
implementation("androidxpose.material:material:1.8.0-alpha07")
implementation("androidxpose.animation:animation:1.8.0-alpha07")

implementation ("androidxpose.foundation:foundation:1.7.6")
implementation ("com.google.accompanist:accompanist-permissions:0.33.2-alpha")
implementation ("com.google.accompanist:accompanist-pager:0.33.2-alpha")
implementation ("io.coil-kt:coil-compose:2.5.0")
implementation("com.google.accompanist:accompanist-pager-indicators:0.33.2-alpha")
implementation("com.google.accompanist:accompanist-systemuicontroller:0.33.2-alpha")
implementation("com.flaviofaria:kenburnsview:1.0.7")
implementation ("androidx.core:core-splashscreen:1.0.1")
//implementation ("com.github.togisoft:jetpack_compose_country_code_picker:1.1.4")
implementation ("com.googlecode.libphonenumber:libphonenumber:8.13.52")
//implementation("com.github.togisoft:ccp:1.")

implementation(platform("com.google.firebase:firebase-bom:32.6.0"))
implementation("com.google.firebase:firebase-analytics")
//implementation("com.google.firebase:firebase-auth-ktx")
implementation("com.google.firebase:firebase-messaging-ktx")

// [START gradle_firebase_ui_auth]
implementation("com.firebaseui:firebase-ui-auth:8.0.2")

implementation("com.jakewharton.timber:timber:5.0.1")
implementation("androidxpose.animation:animation-graphics")
implementation("androidx.media3:media3-exoplayer:1.5.1")
//ui
implementation("androidx.media3:media3-ui:1.5.1")

//maps
implementation("com.google.android.gms:play-services-auth:21.3.0")
implementation("com.google.android.gms:play-services-auth-api-phone:18.1.0")
implementation ("com.google.android.libraries.maps:maps:3.1.0-beta")

implementation ("com.google.android.gms:play-services-location:21.3.0")
implementation("com.google.maps.android:maps-compose:6.4.0")
implementation("com.google.android.gms:play-services-maps:19.1.0")
implementation("com.google.maps.android:android-maps-utils:2.3.0")


implementation("com.google.android.libraries.places:places:4.1.0")
implementation ("com.google.dagger:hilt-android:2.51.1")
implementation ("androidx.lifecycle:lifecycle-viewmodel-ktx:2.8.7")
implementation ("androidx.lifecycle:lifecycle-runtime-compose:2.8.7")
kapt("com.google.dagger:hilt-compiler:2.51.1")

implementation ("com.android.volley:volley:1.2.1")

implementation ("com.google.code.gson:gson:2.10.1")
implementation ("com.githubposeuisuite:ohteepee:1.0.3")
implementation ("com.github.Muratthekus:Compose-CurrencyText:1.0")

implementation ("com.google.api-client:google-api-client:2.0.0")

implementation("com.google.auth:google-auth-library-oauth2-http:1.19.0")
implementation ("com.squareup.retrofit2:retrofit:2.11.0")
implementation ("com.squareup.retrofit2:converter-gson:2.11.0")
implementation("com.karumi:dexter:6.2.3")
implementation ("androidx.work:work-runtime-ktx:2.10.0")
implementation(".greenrobot:eventbus:3.3.1")
implementation ("com.github.bumptech.glide:compose:1.0.0-alpha.1")
implementation ("com.github.DogusTeknoloji:compose-date-picker:1.1.0")
Share Improve this question edited Mar 31 at 22:56 Maria Isabel asked Mar 27 at 22:59 Maria IsabelMaria Isabel 12 bronze badges 1
  • Please do some research before posting. – TechyBenji Commented Apr 1 at 7:37
Add a comment  | 

1 Answer 1

Reset to default 0

You can integrate the Navigation SDK into your Jetpack Compose app to create and manage routes directly within your app. Since you're moving from the Route API to the Navigation SDK, here’s how you can implement it:


1.Setup Dependencies

You'll need to add the Navigation SDK dependencies for your chosen Map provider. If you're using Google Maps, Mapbox, or Huawei Map Kit, their navigation SDKs will differ.

1.1. For Google Maps Navigation SDK

Add this to your build.gradle:

dependencies {     
    implementation "com.google.android.libraries.maps:maps:3.1.0-beta"
    implementation "com.google.maps.android:maps-compose:2.14.0"
    implementation "com.google.maps.android:maps-utils-ktx:3.4.0"     
    implementation "com.google.android.libraries.navigation:navigation:2.5.0" 
} 

2. Display the Map in Compose

Use the GoogleMap Composable from maps-compose.

@Composable
fun MapScreen() {
    val cameraPositionState = rememberCameraPositionState {
        position = CameraPosition.fromLatLngZoom(LatLng(37.7749, -122.4194), 12f)
    }

    GoogleMap(
        modifier = Modifier.fillMaxSize(),
        cameraPositionState = cameraPositionState
    ) {
        Marker(
            state = rememberMarkerState(position = LatLng(37.7749, -122.4194)),
            title = "Destination"
        )
    }
}

3.Request Navigation Route

Use the Navigation SDK to calculate a route.

@Composable
fun NavigationMap(start: LatLng, destination: LatLng) {
    val context = LocalContext.current
    val navController = remember { Navigation.newInstance(context) }

    LaunchedEffect(start, destination) {
        val route = navController.calculateRoute(
            start, destination, TravelMode.DRIVING
        )
        navController.setRoute(route)
    }

    GoogleMap(
        modifier = Modifier.fillMaxSize(),
        cameraPositionState = rememberCameraPositionState {
            position = CameraPosition.fromLatLngZoom(start, 12f)
        }
    ) {
        Polyline(
            points = navController.getRoutePoints(),
            color = Color.Blue,
            width = 5f
        )
    }
}

4. Start Turn-by-Turn Navigation

Once the route is set, you can start turn-by-turn navigation:

Button(onClick = {
    navController.startNavigation()
}) {
    Text("Start Navigation")
}

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论