2017-04-07 60 views
0

我知道這個問題已被多次詢問,但我完全卡住了。我正嘗試使用Intent將EditText值傳遞給Google地圖,以便在我的應用程序之外使用。我有我需要的基本語法,但不知道我在地址中傳遞的位置。我想要使​​用常規地址,而不是緯度/經度。從Android應用程序訪問谷歌地圖導航

我要推出谷歌地圖的代碼是

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 Maps Navigation中。任何幫助將不勝感激!

回答

0

您應該從EditText上提取字符串,並將其附加到URI是這樣的:

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

非常感謝您!對此,我真的非常感激! –

+0

您是否知道如何在抵達目的地後返回活動?或者可以指出我正確的方向?謝謝! - –

+0

如果你沒有明確地調用'finish()',你應該只能使用後退按鈕或向上按鈕。否則,你的應用程序仍然會運行,你可以像任何其他應用程序一樣返回到它。 –