【发布时间】:2019-07-06 22:34:06
【问题描述】:
我正在使用 Android 并构建一个想要在 2 点之间导航的应用。我已经掌握了要点。我在谷歌地图上也有它们之间的路线。我只想在它们之间导航。你能帮我解决这个问题吗?
【问题讨论】:
标签: android google-maps
我正在使用 Android 并构建一个想要在 2 点之间导航的应用。我已经掌握了要点。我在谷歌地图上也有它们之间的路线。我只想在它们之间导航。你能帮我解决这个问题吗?
【问题讨论】:
标签: android google-maps
假设您有两个位置源,目的地,下面的代码会将您重定向到谷歌导航,将其作为一种方法并随时调用!.. 如果您需要任何其他帮助,请告诉我
Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse("http://ditu.google.cn/maps?f=d&source=s_d" +
"&saddr="+source.getLatitude()+
","+source.getLongitude()+"&daddr="+
destination.latitude+
","+destination.longitude+
"&hl=zh&t=m&dirflg=d"));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK & Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
intent.setClassName("com.google.android.apps.maps","com.google.android.maps.MapsActivity");
startActivityForResult(intent, 1);
【讨论】:
您可以尝试使用Directions API。
Google Maps Directions API 是一项使用 HTTP 请求计算位置之间方向的服务。
此服务通常设计用于计算静态(预先已知)地址的方向,以便在地图上放置应用程序内容,但此服务并非旨在实时响应用户输入。
Google Maps Directions API 请求采用以下形式:
https://maps.googleapis.com/maps/api/directions/output?parameters
其中输出可以是以下任一值:
json(推荐)以 JavaScript Object Notation (JSON) 表示输出
xml表示输出为XML
要通过 HTTP 访问 Google Maps Directions API,请使用:
http://maps.googleapis.com/maps/api/directions/output?parameters
对于在请求中包含敏感用户数据(例如用户位置)的应用程序,建议使用 HTTPS。
你需要这个参数来获取路线:
origin - 您希望从中计算方向的地址、文本纬度/经度值或地点 ID。
destination - 您希望计算方向的地址、文本纬度/经度值或地点 ID。目的地参数的选项与上述来源参数的选项相同。
请查看此tutorial 了解更多信息。
【讨论】:
一切正常。
String uri = "http://maps.google.com/maps?f=d&hl=en&saddr="+startingLocation.latitude+","+startingLocation.longitude+"&daddr="+destinationLocation.latitude+","+destinationLocation.longitude;
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(Intent.createChooser(intent, "Select an application"));
【讨论】: