我正在开发一个Android应用程序,其中使用了Google Maps。它运行良好。但是,在加载地图后,当用户单击“获取方向”时,Google Maps会出现方向线,但没有办法获得逐步书写的指示。如果您只是打开Google Maps并获取方向,您可以在地图和方向列表之间切换。
是否有任何API可用于获取Android设备默认Google地图中提供的所有功能?
我正在开发一个Android应用程序,其中使用了Google Maps。它运行良好。但是,在加载地图后,当用户单击“获取方向”时,Google Maps会出现方向线,但没有办法获得逐步书写的指示。如果您只是打开Google Maps并获取方向,您可以在地图和方向列表之间切换。
是否有任何API可用于获取Android设备默认Google地图中提供的所有功能?
获取方向和路线的最佳方式是使用Google Maps的Web服务。它将提供您所需的一切。我已在我的应用程序中使用过它。
以下是一个示例,其中saddr =起始地址,daddr =目标地址(即纬度和经度)。您还可以传递字符串作为地址,而不是lat / lng。
final Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse("http://maps.google.com/maps?" + "saddr="+ latitude + "," + longitude + "&daddr=" + latitude + "," + longitude));
intent.setClassName("com.google.android.apps.maps","com.google.android.maps.MapsActivity");
startActivity(intent);
希望这能帮到您。
在 Scorpion 的代码基础上(该代码完美运行),您可能需要获取当前位置。
Location currentLocation = googleMap.getMyLocation();
double latitudeCurr = currentLocation.getLatitude();
double longitudeCurr = currentLocation.getLongitude();
saddr
表示起始地址
daddr
表示目的地地址
final Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse("+http://maps.google.com/maps?" "saddr="
+ latitudeCurr + "," + longitudeCurr + "&daddr="
+ latitude + "," + longitude));
intent.setClassName("com.google.android.apps.maps",
"com.google.android.maps.MapsActivity");
startActivity(intent);
这是我在应用程序中使用的东西。
https://youtu.be/XVjyIA3f_Ic?t=20m31s
很遗憾,目前此SDK不对公众开放。您需要联系销售团队以购买此SDK的许可证。目前我所看到的只有像Uber或Lyft这样的大型共享乘车公司在其应用程序中拥有此SDK。
或者,您可以使用Google Maps URLs在导航模式下打开Google Maps应用程序。 Google Maps URLs构建了一个通用的、跨平台的URL来启动Google Maps,因此您可以将它们与您的意图一起使用。
例如:
String url = "https://www.google.com/maps/dir/?api=1&destination=Madrid,Spain&origin=Barcelona,Spain&travelmode=driving&dir_action=navigate";
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
为了处理这个问题,我编写了一个开源库,可能会在此过程中帮助您(但需要通知访问权):GMapsParser
您可以通过执行以下操作来获取服务状态:
class NavigationListenerEmitter : NavigationListener() {
override fun onNavigationNotificationAdded(navNotification: NavigationNotification) {
Log.d("notificationListener", "Got initial notification $navNotification")
}
override fun onNavigationNotificationUpdated(navNotification : NavigationNotification) {
Log.d("notificationListener", "Got notification update $navNotification")
}
override fun onNavigationNotificationRemoved(navNotification : NavigationNotification) {
Log.d("notificationListener", "Removed notification $navNotification")
}
}