ofirbt
ofirbt

Reputation: 1896

Starting navigation in Waze with Android's Intents

I have a simple Android app which should be able to allow navigation between 2 GeoPoint's.

I can easily display a GeoPoint on Waze, writing this small piece of code:

String uri = "waze://?ll=40.761043, -73.980545&z=10";
startActivity(new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri)));

But, what I really need is a way to display navigation directions between 2 points. I've tried to locate the correct BroadcastReciever in the Waze source, but I stopped follow when it got to native calls (JNI) because I have no idea where the actual call is... I reached only to the URIHandler signature, with no success finding the implementation...

Any ideas?

Thanks.

Upvotes: 7

Views: 22205

Answers (5)

Payam Monsef
Payam Monsef

Reputation: 336

According to Google doc about working with Waze you can use code below to open waze from your android app:

try {
    // Launch Waze to look for Hawaii:
    String url = "https://waze.com/ul?ll=40.761043,-73.980545&navigate=yes";
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    startActivity(intent);
} catch (ActivityNotFoundException ex) {
    // If Waze is not installed, open it in Google Play:
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.waze"));
    startActivity(intent);
}

Upvotes: 1

dairdr
dairdr

Reputation: 11

You can do [kotlin]:

fun openWaze(latitude: Double, longitude: Double) {
    packageManager?.let {
        val url = "waze://?ll=$latitude,$longitude&navigate=yes"
        val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
        intent.resolveActivity(it)?.let {
            startActivity(intent)
        } ?: run {
            Toast.makeText(context, R.string.noWazeAppFound, Toast.LENGTH_SHORT).show()
        }
    }
}

Upvotes: 1

Claudio Redi
Claudio Redi

Reputation: 68440

Today's Waze base url is https://waze.com/ul so to navigate you have to use

https://waze.com/ul?ll=45.6906304,-120.810983&navigate=yes

Upvotes: 3

TalL
TalL

Reputation: 1681

Fix you uri to:

String uri = "waze://?ll=40.761043, -73.980545&navigate=yes";

(added navigate=yes) and you should be good.

Upvotes: 18

Ami
Ami

Reputation: 387

If this is still relevant you can use this:

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

Upvotes: 14

Related Questions