2017-09-23 74 views
-3

我是Android編程的新手。 這裏是我簡單的代碼,只是爲了啓動給定座標的意圖。問題是,如何獲取我的當前位置,並在Google地圖意圖開始時使用它顯示我的當前位置。如何使用我的當前位置啓動Google地圖的意圖

public void viewroute (View view) 
{ 
    if (view.getId()==R.id.ViewRoute) 
     { 
     Intent intent = new Intent(Intent.ACTION_VIEW); 
       intent.setData(Uri.parse("geo:9.8500,124.1435")); 
     startActivity(intent); 
     } 
} 
+0

歡迎來到Stack Overflow。你遇到的問題究竟是什麼? 請回顧[我如何問一個好問題](https://stackoverflow.com/help/how-to-ask)。你的問題應該包括你的*特定*編碼相關問題的清晰概述,你已經嘗試過的內容以及[最小,完整和可驗證示例]中相關代碼的摘要(https://stackoverflow.com/help/mcve),所以我們有足夠的信息能夠幫助! – FluffyKitten

+0

hello @FluffyKitten我的問題是我想啓動一個谷歌地圖意圖與我目前的位置,在我的例子中它顯示了一個示例座標。我想要的是我目前的座標/位置。 –

+0

你應該更新你的答案和其他任何信息,因爲人們在評論中可能會漏掉ir。 – FluffyKitten

回答

0

你一定要試試這樣

String uri = String.format(Locale.ENGLISH, "geo:%f,%f", latitude, longitude); 
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri)); 
context.startActivity(intent); 

更多信息,請訪問這裏:https://developer.android.com/guide/components/intents-common.html#Maps

,如果你需要的方向遵循這個

Intent intent = new Intent(android.content.Intent.ACTION_VIEW, 
    Uri.parse("http://maps.google.com/maps?saddr=20.344,34.34&daddr=20.5666,45.345")); 
startActivity(intent); 

希望它會幫助你:)

+0

謝謝先生。非常感謝你的幫助! –

相關問題