Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: hyperlink textview to a map location?

I read the documents of Linkify and know how to make a Hyperlink Textview and open browser when user clicks on it, but is there anyway to make a textview(also with a hyperlink look, blue and clickable) but actually shows a map with a pinned location when user clicks on it, for example, in a table:

Hotel ABC

location [some address]

"some address" appears to be a link, but when you click it, instead of showing a web, it shows you a map with the actually address pinned?

Thanks!

like image 911
hzxu Avatar asked May 12 '11 19:05

hzxu


People also ask

How do I make TextView links clickable?

To make them active, you need to // call setMovementMethod() on the TextView object. TextView t2 = (TextView) findViewById(R. id. text2); t2.

Can you make a TextView clickable in android?

In Android, the most common way to show a text is by TextView element. The whole text in the TextView is easy to make clickable implementing the onClick attribute or by setting an onClickListener to the TextView.


1 Answers

The native Android Google Maps app (if available on device) will respond to standard http://maps.google.com URLs and query strings, so something like the following will work:

TextView t = (TextView) findViewById(R.id.mytextview);
t.setText(Html.fromHtml(
   "Location " +
   "<a href=\"http://maps.google.com/maps?q=1+Infinite+Loop,+Cupertino,+Santa+Clara,+California+95014\">" + 
   "1 Infinite Loop, Cupertino, Santa Clara, California 95014" +
   "</a>"));
t.setMovementMethod(LinkMovementMethod.getInstance());
like image 92
Jeff Gilfelt Avatar answered Sep 22 '22 13:09

Jeff Gilfelt