Google Maps Directions intent for bicycle
Asked Answered
S

2

2

When using an intent to launch navigation via Google Maps Directions, is there a way to specify you want a route for walking / bicycle?

Spiritualty answered 17/2, 2015 at 10:39 Comment(0)
L
4

See https://developers.google.com/maps/documentation/directions/

By changing the mode and avoid parameters, the initial request can be modified to return directions for a scenic bicycle journey that avoids major highways.

https://maps.googleapis.com/maps/api/directions/json?origin=Toronto&destination=Montreal&avoid=highways&mode=bicycling&key=API_KEY

Travel Modes

When you calculate directions, you may specify the transportation mode to use. By default, directions are calculated as driving directions. The following travel modes are supported:

driving (default) indicates standard driving directions using the road network. walking requests walking directions via pedestrian paths & sidewalks (where available). bicycling requests bicycling directions via bicycle paths & preferred streets (where available). transit requests directions via public transit routes (where available). If you set the mode to transit, you can optionally specify either a departure_time or an arrival_time. If neither time is specified, the departure_time defaults to now (that is, the departure time defaults to the current time). You can also optionally include a transit_mode and/or a transit_routing_preference.

You can use it like this (code snippet from https://mcmap.net/q/80481/-launching-google-maps-directions-via-an-intent-on-android)

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);
Lonergan answered 17/2, 2015 at 10:49 Comment(0)
S
1

You can set route using intent like this:

val gmmIntentUri = Uri.parse("google.navigation:q="+destintationLatitude+","+destintationLongitude + "&mode=b")
val mapIntent = Intent(Intent.ACTION_VIEW, gmmIntentUri)
mapIntent.setPackage("com.google.android.apps.maps")
startActivity(mapIntent)

Here, "mode=b" is for bicycle.

We can set driving, walking, and bicycling mode by using:

  • d for driving
  • w for walking
  • b for bicycling

You can find more about intent with google maps here.

Note: If there is no route for the bicycle/car/walk then it will show you "Can't find the way there"

Silky answered 12/11, 2018 at 14:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.