How to enable google map navigation in android app

感情迁移 提交于 2020-01-01 05:35:11

问题


I have two points on google map first one is the source and second is the destination, I have the route between these points on the map.Now I want to navigate user from source to destination as Google does on Google Map Like this:-


回答1:


The Google Maps Android API v2 doesn't provide any functionality for navigation. It is in contradiction with Terms of Service of Maps APIs. Have a look at section 10.4 c (iii) of ToS:

No navigation. You will not use the Service or Content for or in connection with (a) real-time navigation or route guidance; or (b) automatic or autonomous vehicle control.

https://developers.google.com/maps/terms#section_10_4

If you need navigation you should create an intent that opens the Google Maps app in navigation mode. There is a Google Maps URLs that allows to construct a universal, cross-platform URL to launch Google Maps intents from your application. You can open navigation mode of native app following this documentation:

https://developers.google.com/maps/documentation/urls/guide#directions-action

Hope this helps!




回答2:


There is a way to stimulate a view like that but not embedded like uber but very close.

 public void loadNavigationView(String lat,String lng){
    Uri navigation = Uri.parse("google.navigation:q="+lat+","+lng+"");
    Intent navigationIntent = new Intent(Intent.ACTION_VIEW, navigation);
    navigationIntent.setPackage("com.google.android.apps.maps");
    startActivity(navigationIntent);
}

You call the method and provide the latitude and longitude.It will launch Google map navigation.Like uber



来源:https://stackoverflow.com/questions/44734051/how-to-enable-google-map-navigation-in-android-app

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