繁体   English   中英

Android中的Google Maps Navigation

[英]Google Maps Navigation in Android

我正在使用Android,正在构建一个要在2点之间导航的应用程序。 我已经有了要点。 我在谷歌地图上也有它们之间的路线。 我只想在它们之间导航。 您能帮我吗?

考虑到您有两个位置的来源,目的地,下面的代码将您重定向到google导航,将其作为方法并在需要时调用!..让我知道您是否需要其他帮助

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?参数

其中输出可能是以下值之一:

  • json(推荐)指示以JavaScript对象表示法(JSON)输出

  • xml表示输出为XML

要通过HTTP访问Google Maps Directions API,请使用:

http://maps.googleapis.com/maps/api/directions/output?参数

建议将HTTPS用于在请求中包含敏感用户数据(例如用户位置)的应用程序。

您需要此参数来获取路线:

  • origin您希望从中计算路线的地址,文本纬度/经度值或地点ID。

  • destination -您要计算路线的地址,文本纬度/经度值或地点ID。 如上所述,目标参数的选项与原始参数的选项相同。

另请参阅本教程以获取更多信息。

一切正常。

 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"));

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM