4

This is how i am getting current location. Now my question is that is there any way to make this latitude and longitude a link where user can click and there current position will be shown on GoogleMap . Because i will be sending this link via text message to another android and when he clicks on that link Google map install in his mobile will open or the Googlemap website will be open and the location get by lang and lat will be shown on map. Don't know how to achieve it any help ?

   public void onLocationChanged(Location location) {

            mLocationView.setText("Location received: "+ location.getLatitude() + location.getLongitude());
Brendom
  • 123
  • 1
  • 10

2 Answers2

2

Use the below code

String uri = String.format(Locale.ENGLISH, "geo:%f,%f", latitude, longitude);
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
context.startActivity(intent);
Sai Phani
  • 462
  • 3
  • 6
  • This doesn't exactly answer the question. He's asking how to construct a link that will be sent in a SMS message. – Daniel Nugent Apr 14 '15 at 17:01
  • yes @DanielNugent thats what i am asking construct link with my latitude and longitude which will open googlemap and show me the location – Brendom Apr 14 '15 at 17:05
  • @Brendom From where you will send sms, Is you SMS Gateway is always same. I mean SMS sender always same?? – Sai Phani Apr 14 '15 at 17:16
2

For a simple URL to be constructed that you can add to a SMS message, you could just do something like this:

String link = "http://maps.google.com/maps?q=loc:" + String.format("%f,%f", location.getLatitude() , location.getLongitude() );

For example, this code:

double lat = 37.77657;
double lon = -122.417506;
String link = "http://maps.google.com/maps?q=loc:" + String.format("%f,%f", lat, lon);

Constructs a link like this:

http://maps.google.com/maps?q=loc:37.776570,-122.417506

For more info, see this question.

Community
  • 1
  • 1
Daniel Nugent
  • 43,104
  • 15
  • 109
  • 137