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

十年热恋 提交于 2019-12-04 08:31:40
Siddharth Lele

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

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