Reputation: 123
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());
Upvotes: 4
Views: 7777
Reputation: 43322
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.
Upvotes: 2
Reputation: 462
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);
Upvotes: 2