简体   繁体   English

从Android应用程序访问Google Maps Navigation

[英]Accessing Google Maps Navigation from Android Application

I know this question has been asked multiple times, but I'm completely stuck. 我知道这个问题已经被问过多次了,但是我完全陷入了困境。 I am trying to use an Intent to pass an EditText value to Google Maps to use outside of my app. 我正在尝试使用Intent将EditText值传递给Google Maps以在我的应用程序之外使用。 I have the basic syntax that I need, but not sure where I pass in the address. 我有所需的基本语法,但不确定地址中的传递位置。 I'm wanting to use a regular address and not latitude/longitude. 我想使用常规地址,而不是纬度/经度。

The code I have to launch Google Maps is 我必须启动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);
}

And my XML for the value that I want passed in... 还有我要传递的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" />

I'm just wanting to take the text that is input in the address's EditText box and put into Google Maps Navigation as the destination using my current location upon clicking the "Route" button. 我只想将在地址的EditText框中输入的文本用作我的当前位置,然后单击“ Route”按钮,将其作为目标放到Google Maps Navigation中。 Any help would be greatly appreciated! 任何帮助将不胜感激!

You should extract the string from the EditText and attach it to the Uri like this: 您应该从EditText中提取字符串,并将其附加到Uri,如下所示:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM