【问题标题】:Navigate from current location to another location via google maps directions通过谷歌地图方向从当前位置导航到另一个位置
【发布时间】:2020-11-18 13:11:57
【问题描述】:

谷歌地图开发人员有没有办法或是否有一个框架,用于使用 kotlin 在 android stuio 谷歌地图中从您的位置到您尝试去的地理位置。我正在寻找一些解决方案,但我似乎很难找到即使在谷歌地图开发人员中阅读也没有。

【问题讨论】:

    标签: android-studio kotlin google-maps-android-api-2


    【解决方案1】:

    您可以使用显式 Intent 启动 Google 地图应用,并将目的地坐标作为 Intent 参数。

    // Create a Uri from an intent string. Use the result to create an Intent.
    val googleMapsIntentUri = Uri.parse(
        "google.navigation:q=$destination_latitude,$destination_longitude"
    )
    
    // Create an Intent from googleMapsIntentUri. Set the action to ACTION_VIEW
    val mapIntent = Intent(Intent.ACTION_VIEW, googleMapsIntentUri)
    // Make the Intent explicit by setting the Google Maps package
    mapIntent.setPackage("com.google.android.apps.maps")
    
    // Attempt to start an activity that can handle the Intent
    startActivity(mapIntent)
    

    【讨论】:

    • 我建议使用 Google Maps URLs 作为 URI。这是 Google 推荐的,因为他们在几年前推出了 Maps URLs API。
    • 那么你如何在 android studio 上使用它呢? @xomena
    • 使用地图网址字符串"https://www.google.com/maps/dir/?api=1&your_parameters",而不是字符串"google.navigation:q=$destination_latitude,$destination_longitude"
    猜你喜欢
    • 1970-01-01
    • 2017-03-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-06
    相关资源
    最近更新 更多