Question:
I have the url https://www.google.com/maps/@41.3825581,2.1704375,16z
that positions Barcelona on the map, but I find that it does not come out, let's say the direction pointer, it only centers the map on you.
On my device I have several map apps:
- Cytymapper
- MAPS.ME
- Google maps
- Google Earth
The code I have to launch the Intent
:
Uri uri = Uri.parse("https://www.google.com/maps/@41.3825581,2.1704375,16z");
if (URLUtil.isValidUrl(uri.toString())) {
startActivity( new Intent(Intent.ACTION_VIEW, uri));
}
I get an ActionList
to choose Maps
or Chrome
, if I click on Maps
it opens the maps
application, but it does not show me the position with an indicator, it focuses on landmark and point.
If I indicate that it opens with chrome
, another ActionList
comes out, with the other map applications.
My doubts are:
- How do I launch a specific
Intent
so that it can be opened with the Maps Apps? - How can I visualize the position marker within the map?
Solved:
To display a location with a marker and label
geo:<lat>,<lon>?z=<zoom>&q=<lat>,<lon>(<label>)
To show the location of Barcelona
geo:41.3825581,2.1704375?z=16&q=41.3825581,2.1704375(Barcelona)
To show the ActionList
that all the compatible applications appear to position a location
Uri uri = Uri.parse("geo:41.3825581,2.1704375?z=16&q=41.3825581,2.1704375(Barcelona)");
startActivity( new Intent(Intent.ACTION_VIEW, uri));
If you want to send the position directly to the Google Maps application
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse("geo:41.3825581,2.1704375?z=16&q=41.3825581,2.1704375(Barcelona)"));
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
startActivity(intent);
Answer:
According to this answer in SO in English:
The form is this:
Uri intentUri = Uri.parse("geo:41.382,2.170?z=16&q=41.382,2.170(Esta+Es+La+Etiqueta)");
Intent intent = new Intent(Intent.ACTION_VIEW, intentUri);
startActivity(intent);