Once user presses button in my application, I would like to open standard Google Map application and to show particular location. How can I do it? (without using com.g
You should create an Intent
object with a geo-URI:
String uri = String.format(Locale.ENGLISH, "geo:%f,%f", latitude, longitude);
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
context.startActivity(intent);
If you want to specify an address, you should use another form of geo-URI: geo:0,0?q=address
.
reference : https://developer.android.com/guide/components/intents-common.html#Maps
To go to location WITH PIN on it, use:
String uri = "http://maps.google.com/maps?q=loc:" + destinationLatitude + "," + destinationLongitude;
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
intent.setPackage("com.google.android.apps.maps");
startActivity(intent);
for without pin, use this in uri:
String uri = "geo:" + destinationLatitude + "," + destinationLongitude;
You can also use the code snippet below, with this manner the existence of google maps is checked before the intent is started.
Uri gmmIntentUri = Uri.parse(String.format(Locale.ENGLISH,"geo:%f,%f", latitude, longitude));
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
mapIntent.setPackage("com.google.android.apps.maps");
if (mapIntent.resolveActivity(getPackageManager()) != null) {
startActivity(mapIntent);
}
Reference: https://developers.google.com/maps/documentation/android-api/intents