Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get driving directions using Google Maps API v2

I am trying to get the driving direction between the two positions:

LatLng(12.917745600000000000,77.623788300000000000) LatLng(12.842056800000000000,7.663096499999940000) 

The code which i have tried:

Polyline line = mMap.addPolyline(new PolylineOptions().     add(new LatLng(12.917745600000000000,77.623788300000000000),     new LatLng(12.842056800000000000,7.663096499999940000))        .width(5).color(Color.RED)); 

But this draws a straight line between the two points .

Is there any other method/way to get the driving directions between these two points.

like image 614
Anukool Avatar asked Jan 24 '13 06:01

Anukool


People also ask

How do I get Google Maps API directions?

Go to the Google Maps Platform > Credentials page. On the Credentials page, click Create credentials > API key. The API key created dialog displays your newly created API key. Click Close.

Is google Directions API free?

The Directions API uses a pay-as-you-go pricing model. Directions API requests generate calls to one of two SKUs depending on the type of request: basic or advanced. Along with the overall Google Terms of Use, there are usage limits specific to the Directions API.

Can I use direction API for free?

There is no more "free", although Google does (at present), give you some usage without charging.


2 Answers

I just release my latest library for Google Maps Direction API on Android https://github.com/akexorcist/Android-GoogleDirectionLibrary

like image 177
Akexorcist Avatar answered Oct 06 '22 00:10

Akexorcist


This is what I am using,

Intent intent = new Intent(android.content.Intent.ACTION_VIEW,  Uri.parse("http://maps.google.com/maps?saddr="+latitude_cur+","+longitude_cur+"&daddr="+latitude+","+longitude)); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addCategory(Intent.CATEGORY_LAUNCHER );      intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity"); startActivity(intent); 
like image 20
Basim Sherif Avatar answered Oct 05 '22 22:10

Basim Sherif