以编程方式在google maps android中设置从位置到当前位置
我正在创建一个应用程序,它需要打开谷歌地图以步行模式导航到一个地方,并将源/从位置设置为当前位置 这是我使用的代码以编程方式在google maps android中设置从位置到当前位置,android,google-maps,google-maps-urls,Android,Google Maps,Google Maps Urls,我正在创建一个应用程序,它需要打开谷歌地图以步行模式导航到一个地方,并将源/从位置设置为当前位置 这是我使用的代码 String url = "https://maps.google.co.in/maps?q=" + destination + "&mode=walking"; Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_T
String url = "https://maps.google.co.in/maps?q=" + destination + "&mode=walking";
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getApplicationContext().startActivity(intent);
如何将“从位置”设置为“当前位置”??
谢谢。我建议使用,而不是您在示例中提供的链接。谷歌地图URL是在移动设备和web浏览器上启动谷歌地图应用程序的官方推荐方式
请注意,如果在Google Maps URL中省略origin
参数,API将使用当前位置(如果可用)
原点:定义显示方向的起点默认为最相关的起始位置,如用户位置(如果可用)。如果没有,则生成的映射可能会提供一个空白表单,以允许用户输入原点。该值可以是地名、地址或以逗号分隔的纬度/经度坐标。应该对字符串进行URL转义
因此,您应该将代码重写为
String url = "https://www.google.com/maps/dir/?api=1&destination=" + destination + "&travelmode=walking&dir_action=navigate";
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getApplicationContext().startActivity(intent);
我希望这有帮助