Domanda

I'm trying to start a navigation activity with an intent from my app. I want it to start navigation from my location to a point that I provide. I've tried this way

String uri = "geo: "+String.valueOf(latitude) + "," + String.valueOf(longitude);
context.startActivity(new Intent(android.content.Intent.ACTION_VIEW,
                            Uri.parse(uri)));

It works great when I choose to navigate with Waze (it starts with the "start navigation" dialog right away), but doesnt work with maps (only shows the point, not the navigation option)

If I use this way

Intent intent = 
            new Intent(Intent.ACTION_VIEW,
                    Uri.parse("http://maps.google.com/maps?"  + 
                            "&daddr=" + String.valueOf(latitude) + "," 
                             + String.valueOf(longitude)));
context.startActivity(intent);

Its the opposite, starting the navigation with maps and only showing the point with Waze

Thanks!

È stato utile?

Soluzione

I've done this myself and have had no issues using it the following way:

intent.setData(Uri.parse("geo:" + getLatitude() + "," + 
    getLongitude() + "?q=" + getStreet() + "+" + 
    getHousenumber() + "+" + getPostalcode() + "+" + 
    getCity()));

The difference is that I use "&q=" for the query as stated by Google.

See: https://developer.android.com/guide/components/intents-common.html#Maps

Altri suggerimenti

This is a simple way and works on both of them:

Java

String uri = "geo:?q= latitude,longtitude";
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(uri)));

Kotlin

val uri = "geo:?q=$latitude,$longtitude"
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(uri)))

I hope this will be useful

ok Google maps

    final String uri="http://maps.google.com/maps?f=d&hl=de&geocode=&saddr=" + Global.lattaxi + "," + Global.lontaxi + "&daddr=" + Global.latcliente + "," + Global.loncliente + "&ie=UTF8";
     final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));

    intent.setComponent(new ComponentName(
            "com.google.android.apps.maps",
            "com.google.android.maps.MapsActivity"));
    startActivity(intent);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top