3

How can i start an Intent to open either the default navigation application (e.g. Google Navigation or Google Maps) or give the user the opportunity to select among navigation applications.

Thanks in advance.

2 Answers 2

4

You have to use an Intent with ACTION_VIEW and the geo data scheme.

The problem using geo:latitude,longitude is that Google Maps only centers at your point, without any pin or label.

That's quite confusing, especially if you need to point to a precise place or/and ask for directions.

If you use the query parameter geo:lat,lon?q=name in order to label your geopoint, it uses the query for search and dismiss the latitude and longitude parameters.

I found a way to center the map with latitude and longitude and display a pin with a custom label, very nice to display and useful when asking for directions or any other action:

Intent intent = new Intent(android.content.Intent.ACTION_VIEW, 
Uri.parse("geo:0,0?q=37.423156,-122.084917 (" + name + ")");
startActivity(intent);

This intent is from the list of official "G apps" intent list here.

2

Try:

Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("google.navigation:q=New+York+NY")); startActivity(i);

Or use this, this way the stardard navigation app will be launched:

Intent intent = new Intent(android.content.Intent.ACTION_VIEW, 
Uri.parse("http://maps.google.com/maps?saddr=20.344,34.34&daddr=20.5666,45.345"));
startActivity(intent);

Add this line before startActivity if you don't want the popup dialog:

intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");

Also see: How to check programmatically if an application is installed or not in Android? and Android: detect when app is installed, you can make your own Window so the user can choose between some application.

2
  • I tried both your suggestions, but the first just opens Google Navigation and the other only opens the possibility of choosing: (my two browsers or Google Maps, NOT e.g. Google Navigation)
    – Noloxs
    Jan 17, 2013 at 10:20
  • I would like it to give the possibility of choosing both Google Maps and Google Navigation or whatever app the user might have installed to Navigate or get directions. But i don't even know if that is possible.
    – Noloxs
    Jan 17, 2013 at 10:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.