Android google.navigation Intent Modes?

荒凉一梦 提交于 2020-01-20 04:11:12

问题


I'm currently developing an application that will launch a navigation intent. I know that this isn't an official API, but it works perfectly the way I want it to.

I allow the user to select driving, walking, and bus navigation to a location. The intent to launch directly into Google Maps Navigation looks like this:

google.navigation:ll= + a latitude and longitude, then + &mode= then your mode of transportation. For example, to navigate using walking directions to a certain area:

google.navigation:ll=blah,blah&mode=w

Driving is default, or &mode=d, and biking is &mode=b, but I can't figure out bus (public transit).

Has anyone done this before?

Thanks!

Edit: So far, I've found that mode=public gives bike directions, mode=transit gives driving, frustratingly, mode=bus also returns bike directions.

More: mode=train also gives driving... There's GOT to be a way to do this...

Another Edit: I realized just now that I'm pretty sure that it doesn't exist, because after experimenting with terms I realized that I should instead launch a Google Maps intent with a bus search, but does anyone know how to do this?


回答1:


After a bunch of guessing and hunting around, I have decided that it is impossible to launch directly to bus navigation, because that would involve CHOOSING a bus for the person to ride, which wouldn't make sense.

Instead, you can launch them to a Google Maps search to the destination like so, thank you to this answer to a similar question:

"http://maps.google.com/maps?daddr=lat,long&dirflg=r"

With the &dirflag specifying public transit. (Why the "r" I have no idea...)




回答2:


You should be able to append the travel mode as needed, with the travel modes listed below.

  • 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 would like to launch an Intent and allow the user to select between Maps or Browser you can do it this way.

Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?saddr="+ starting_point_lat+","+starting_point_long+"&daddr="+dest_point_lat+","+dest_point_long+"&mode=transit"));
startActivity(intent);


来源:https://stackoverflow.com/questions/13255192/android-google-navigation-intent-modes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!