Android中的Google地图导航

时间:2016-04-15 07:57:59

标签: android google-maps

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

3 个答案:

答案 0 :(得分:0)

考虑您有两个位置来源,目的地,以下代码会将您重定向到谷歌导航,将其作为一种方法,并在您需要时拨打电话!..如果您需要任何其他帮助,请告诉我

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

答案 1 :(得分:0)

You can try to use Directions API.

The Google Maps Directions API is a service that calculates directions between locations using an HTTP request.

This service is generally designed for calculating directions for static (known in advance) addresses for placement of application content on a map, however this service is not designed to respond in real time to user input.

A Google Maps Directions API request takes the following form:

https://maps.googleapis.com/maps/api/directions/output?parameters

where output may be either of the following values:

  • json (recommended) indicates output in JavaScript Object Notation (JSON)

  • xml indicates output as XML

To access the Google Maps Directions API over HTTP, use:

http://maps.googleapis.com/maps/api/directions/output?parameters

HTTPS is recommended for applications that include sensitive user data, such as a user's location, in requests.

You need this parameter in getting the directions:

  • origin - The address, textual latitude/longitude value, or place ID from which you wish to calculate directions.

  • destination - The address, textual latitude/longitude value, or place ID to which you wish to calculate directions. The options for the destination parameter are the same as for the origin parameter, described above.

Check also this tutorial for more information.

答案 2 :(得分:0)

一切正常。

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