2

enter image description hereenter image description here

I have a code where I'm retrieving latitude and longitude information. I'm interested to show that information on map. I would like to create a link for Google map with retrieved "longitude" and "latitude" information. I am using Linkify for this as follows:

**** Java Code**:

 String text = "maps.google.com/?q=latitude,longitude";
 TextView label = (TextView)findViewById(R.id.textView);
 label.setText(text);
 Pattern pattern = Pattern.compile("maps.google.com");
 Linkify.addLinks(label, pattern, "http://");

But this code is not working. Can someone help me with code? I am getting something like following. My longitude and latitude are not getting linked with rest of the url.

Cœur
  • 37,241
  • 25
  • 195
  • 267
sonia
  • 405
  • 2
  • 7
  • 23

2 Answers2

2

you may use below code for displaying map

    String url = "geo:" +  sLatitude + "," + sLongitude +"?z=22&q="+sLatitude + "," + sLongitude;
    Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(url));
    startActivity(intent);

above code shows map using google map application installed in your phone, it also mark the location with zoom level of 22. No google map api key required

Hope this will help...

Riskhan
  • 4,434
  • 12
  • 50
  • 76
  • i dont wanna display map itself with intent .I want the hyperlink comes over the textview from there if i click then the google map gets opened with latitude longitude information in my code.and after that this link send as SMS to other .... – sonia Feb 25 '13 at 06:28
0

You may also use the android:autoLink attribute of the TextView to convert the string into links. It controls whether links such as urls and email addresses are automatically found and converted to clickable links.

For example, you may add it in your layout (.xml) file.

<TextView 
    android:id="@+id/google_map_url"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:autoLink="web" />

It will automatically convert the text into links for you. Hope it helps you :)

Ibungo
  • 1,137
  • 12
  • 23