我正在使用谷歌地图意图获取路线。问题是,无论我在谷歌地图应用程序中搜索的最后一种方向,都会提供指示。
例如,如果我使用谷歌地图最后获取步行路线,当我使用我的应用程序时,路线将自动搜索步行路线。
我想让用户能够选择他们的方向类型。
以下是代码段:
String directions = "http://maps.google.com/maps?saddr=" + myLocationString + "&daddr=" + officeLocationString;
// Create Google Maps intent from current location to target location
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse(directions));
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
fcontext.startActivity(intent);
答案 0 :(得分:4)
我无法使用上面的“& directionsmode =”,它只是被忽略了。我在网页浏览器中使用谷歌地图中的URL进行了一些修补,我发现“& dirflg”工作得更好,无论是在浏览器中还是在Android操作系统中。
使用这些值:r =运输,b =骑自行车,d =驾驶,w =行走
答案 1 :(得分:2)
修改:截至2013年1月,Google Directions API已更新,结果现在以JSON格式提供。网址格式现在看起来像这样:
http://maps.googleapis.com/maps/api/directions/xml?origin=Chicago,IL&destination=Los+Angeles,CA&waypoints=Joplin,MO|Oklahoma+City,OK&sensor=false
有更多信息here。
将directionsmode
参数添加到您的URI应该可以满足您的需求。
directionsmode:运输方式。可以设置为:驾驶,公交或步行。
所以也许你可以尝试类似的东西:
String directions = "http://maps.google.com/maps?saddr=" + myLocationString + "&daddr=" + officeLocationString + "&directionsmode=" + directionsMode;