簡體   English   中英

Google Maps Intent參數

[英]Google maps intent parameters

我想傳遞參數取自Google地圖中的edittext。

public void nav() {
 String address = edit.getText().toString();
 address = address.replace(" ","+");
 String city = address.substring(address.lastIndexOf(" ") + 1);
 Intent i = new Intent(Intent.ACTION_VIEW, uri.parse("geo:0,0?q="+city));
 startActivity(i);
}

為什么String city = address.substring(address.lastIndexOf(" ") + 1); 因為其目的不得不開始只有在EditText上有字bring 因此,只有在有人寫信時地圖才開始:例如bring me New york 。“問題”是,實際上,地圖應用程序需要整個字符串,而不僅僅是城市。 我試過了子字符串,但不起作用。

問題是沒有空格,因為您只用“ +”替換了所有空格,因此,如果您要用戶寫“給我帶來”(地名),則可以嘗試以下操作:

try {


String address = edit.getText().toString();
address = address.replace(" ","+");
address = address.substring(9);
Intent i = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse("geo:0,0?q="+address));
startActivity(i);

}

catch (Exception e){
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM