Is there an Android equivalent to Google Maps URL scheme for iOS?

浪子不回头ぞ 提交于 2019-12-06 03:32:11

问题


I want to open Google Maps in Navigation mode from a mobile web link. This seems easy enough for iOS devices using https://developers.google.com/maps/documentation/ios/urlscheme

Is there an equivalent for Android? All I could find was this: https://developer.android.com/guide/appendix/g-app-intents.html

But that doesn't allow you to specify "transitmode" and the other parameters needed to get directions as far as I can tell.


回答1:


Actually, a slight modification of the methods described in the iOS Doc would work here too (I tested it before putting it here albeit, in a native app and not a web link).

The parameters necessary for this to work are pretty much the same as with the ones listed in the iOS documentation:

From the iOS Docs:

Parameters:

  • saddr: Sets the starting point for directions searches. This can be a latitude,longitude or a query formatted address. If it is a query string that returns more than one result, the first result will be selected. If the value is left blank, then the user’s current location will be used.
  • daddr: Sets the end point for directions searches. Has the same format and behavior as saddr.
  • directionsmode: Method of transportation. Can be set to: driving, transit, or walking.

They are actually, pretty much the same. They are however, no where to be found in the documents. Also, while the first 2 parameters work the usual way here, the last parameter directionsmode does not work as is. A workaround is however, listed below.

That being said, a simple URL can be constructed that can then be passed as an Uri to an Intent that will then handle the application to be launched (Google Maps if installed and/or list of browsers to choose from)

String mapURL = http://maps.google.com/maps?saddr=-33.9417, 150.9473&daddr=-33.92050, 151.04287&dirflg=d
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(mapURL));
startActivity(intent);

A few variations for the Transit Mode:

  1. &dirflg=d = for Driving directions (this is the default mode. leaving it out is the same as putting it in explicityly).
  2. &dirflg=w = for Walking directions
  3. &dirflg=r = for Public transit.
  4. &dirflg=b = for Biking directions.

That being said, at the time of running these test (I admit I was curious enough to test a little further after seeing this question ;-) ), the modes listed in the Travel Modes section don't seem work!

A little proof of sorts:

Note: Credit for the initial discovery of the options



来源:https://stackoverflow.com/questions/17915901/is-there-an-android-equivalent-to-google-maps-url-scheme-for-ios

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