【问题标题】:Accessing Google Maps Navigation from Android Application从 Android 应用程序访问 Google 地图导航
【发布时间】:2017-04-07 04:02:56
【问题描述】:

我知道这个问题已被多次问过,但我完全陷入困境。我正在尝试使用 Intent 将 EditText 值传递给 Google Maps 以在我的应用程序之外使用。我有我需要的基本语法,但不确定我在哪里传递地址。我想使用常规地址,而不是纬度/经度。

我必须启动谷歌地图的代码是

public void sendMessage(View view)
{
    Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
            Uri.parse("http://maps.google.com/maps?daddr=address"));
    startActivity(intent);
}

还有我想要传入的值的 XML...

<EditText
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/addressEditText"
        android:layout_weight=".5"
        android:layout_marginRight="50dp"
        android:layout_marginBottom="-10dp"
        android:textColor="@android:color/primary_text_light"
        android:singleLine="true"
        android:padding="1dp"
        android:scaleType="centerCrop"
        android:cropToPadding="true"
        android:background="@drawable/border_image"/>

<Button
        android:id="@+id/routeButton"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="-60dp"
        android:layout_marginRight="40dp"
        android:layout_marginBottom="-10dp"
        android:layout_marginTop="-10dp"
        android:layout_weight=".4"
        android:text="Route"
        android:textColor="#FFF"
        android:textSize="16sp"
        android:onClick="sendMessage" />

我只是想在点击“路线”按钮后使用我当前的位置将在地址的 EditText 框中输入的文本作为目的地放入 Google 地图导航中。任何帮助将不胜感激!

【问题讨论】:

    标签: android google-maps android-intent


    【解决方案1】:

    您应该从 EditText 中提取字符串并将其附加到 Uri,如下所示:

    String map = "http://maps.google.co.in/maps?q=" + yourAddress;
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(map));
    startActivity(intent);
    

    【讨论】:

    • 非常感谢!我真的很感激!
    • 你知道到达目的地后如何返回活动吗?或者可以指出我正确的方向?谢谢! -
    • 如果您没有在活动上明确调用finish(),您应该只能使用后退按钮或向上按钮。否则,您的应用程序仍将运行,您可以像其他任何应用程序一样返回到它。
    • 太棒了 :) 非常感谢您的帮助!
    猜你喜欢
    • 1970-01-01
    • 2011-03-31
    • 2012-01-23
    • 1970-01-01
    • 2018-07-20
    • 1970-01-01
    • 2013-02-12
    • 2021-12-18
    • 1970-01-01
    相关资源
    最近更新 更多