I want passing parameters taking from a edittext in the google maps.. the method:
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);
}
why String city = address.substring(address.lastIndexOf(" ") + 1);
? Because the intent have to start only if in the edittext there is the word bring
. So maps starts only if anyone write: bring me New york
for example.. The "problem" is that actually the maps application takes the whole string and not only the city. I tried with the substring but not works.. Any way?
The problem is that there are no spaces because you just replaced them all with "+" so if you want the user to write "bring me" (place name) than try this:
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){
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.