autoLink for map not working

筅森魡賤 提交于 2019-12-18 20:47:41

问题


I have the following TextView in my XML layout file:-

<TextView  
   android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:text="@string/autolink_test"
       android:autoLink="all"
/>

The string autolink_test contains a phone number, an email address, a website address and a physical geographical address.

While the first three are showing up correctly as clickable autolinks, the address does not. Only the zipcode part shows up as an autolink... and that too as a phone number! (When I click it, the phone dialer starts up with that number).

Any help would be appreciated.


回答1:


Alternative to it, in case if autolink doesn't work

Add links to your texview . Get it underline as folows :

SpannableString spanStr = new SpannableString(buf.toString());
spanStr.setSpan(new UnderlineSpan(), 0, spanStr.length(), 0);
iTextView.setText(spanStr);

Use the following code to open it with map app on click as follows :

Intent geoIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("geo:0,0?q="
                                +iTextView.getText().toString()));
startActivity(geoIntent);



回答2:


OK, I figured out what was causing the problem. Just thought I will leave the answer here in case someone else runs into the same problem.

If the street address is not properly capitalized, it is not read properly as the address!

Here is my XML autolink_test string:

<string name="autolink_test">Name: New York Times \n
   Email: public@nytimes.com \n
   Phone: 212-556-7652 \n
   Address: 620 Eighth Avenue New York, NY 10018  \n
   Address: 620 Eighth avenue New York, NY 10018  \n
   Website: http://www.nytimes.com
</string>

The first address shows up correctly as an autolink. The second one (with a small 'a' in 'avenue') does not show up correctly.

This seems a little strange to me as the google maps website certainly doesn't care about such niceties.

Anyways, so here it is :-)



来源:https://stackoverflow.com/questions/2624649/autolink-for-map-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!