Drawing driving route directions between two locations using Google Directions in Google Map Android API V2

March 12, 2013

In this article, we will develop an Android application which facilitates users to tap two locations in the Google Map. On taping the second point, a driving route will be drawn in the Google Map Android API V2 using Google Directions API.

This application is developed in Eclipse (4.2.1) with ADT plugin (21.1.0) and Android SDK (21.1.0) and tested in a real device (Android 2.3.6  -  GingerBread ).

1. Create a new Android application project namely “LocationRouteDirectionMapV2″

Create a new Android Application project

Figure 1 : Create a new Android Application project

2. Configure the project

Configure the application project

Figure 2 : Configure the application project

3. Design application launcher icon

Design application launcher icon

Figure 3 : Design application launcher icon

4. Create a blank activity

Create a blank activity

Figure 4 : Create a blank activity

5. Enter MainActivity details

Enter MainActivity details

Figure 5 : Enter MainActivity details

6. Download and configure Google Play Services Library in Eclipse

Google Map for Android is now integrated with Google Play Services. So we need to set up Google Play Service Library for developing Google Map application in Android.

Please follow the given below link to setup Google Play Service library in Eclipse.


Note : Please ensure that, the latest version of Google Play Service Library is installed

7. Add Google Play Services Library to this project

Link Google Play Services Library to this project

Figure 6 : Link Google Play Services Library to this project

8. Get the API key for Google Maps Android API V2

We need to get an API key from Google to use Google Maps in Android application.

Please follow the given below link to get the API key for Google Maps Android API v2.


9. Add Android Support library to this project

By default, Android support library (android-support-v4.jar ) is added to this project by Eclipse IDE to the directory libs. If it is not added, we can do it manually by doing the following steps :

  • Open Project Explorer by Clicking “Window -> Show View -> Project Explorer”
  • Right click this project
  • Then from popup menu, Click “Android Tools -> Add Support Library “

10. Update the layout file res/layout/activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    tools:context=".MainActivity" >
        class="com.google.android.gms.maps.SupportMapFragment" />


11. Create a new class namely “DirectionsJSONParser” in the file src/in/wptrafficanalyzer/locationroutedirectionmapv2/DirectionsJSONParser.java

package in.wptrafficanalyzer.locationroutedirectionmapv2;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.google.android.gms.maps.model.LatLng;

public class DirectionsJSONParser {

    /** Receives a JSONObject and returns a list of lists containing latitude and longitude */
    public List<List<HashMap<String,String>>> parse(JSONObject jObject){

        List<List<HashMap<String, String>>> routes = new ArrayList<List<HashMap<String,String>>>() ;
        JSONArray jRoutes = null;
        JSONArray jLegs = null;
        JSONArray jSteps = null;

        try {

            jRoutes = jObject.getJSONArray("routes");

            /** Traversing all routes */
            for(int i=0;i<jRoutes.length();i++){
                jLegs = ( (JSONObject)jRoutes.get(i)).getJSONArray("legs");
                List path = new ArrayList<HashMap<String, String>>();

                /** Traversing all legs */
                for(int j=0;j<jLegs.length();j++){
                    jSteps = ( (JSONObject)jLegs.get(j)).getJSONArray("steps");

                    /** Traversing all steps */
                    for(int k=0;k<jSteps.length();k++){
                        String polyline = "";
                        polyline = (String)((JSONObject)((JSONObject)jSteps.get(k)).get("polyline")).get("points");
                        List<LatLng> list = decodePoly(polyline);

                        /** Traversing all points */
                        for(int l=0;l<list.size();l++){
                            HashMap<String, String> hm = new HashMap<String, String>();
                            hm.put("lat", Double.toString(((LatLng)list.get(l)).latitude) );
                            hm.put("lng", Double.toString(((LatLng)list.get(l)).longitude) );

    } catch (JSONException e) {
    }catch (Exception e){

    return routes;
    * Method to decode polyline points
    * Courtesy : http://jeffreysambells.com/2010/05/27/decoding-polylines-from-google-maps-direction-api-with-java
    * */
    private List<LatLng> decodePoly(String encoded) {

        List<LatLng> poly = new ArrayList<LatLng>();
        int index = 0, len = encoded.length();
        int lat = 0, lng = 0;

        while (index < len) {
            int b, shift = 0, result = 0;
            do {
                b = encoded.charAt(index++) - 63;
                result |= (b & 0x1f) << shift;
                shift += 5;
            } while (b >= 0x20);
            int dlat = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));
            lat += dlat;

            shift = 0;
            result = 0;
            do {
                b = encoded.charAt(index++) - 63;
                result |= (b & 0x1f) << shift;
                shift += 5;
            } while (b >= 0x20);
            int dlng = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));
            lng += dlng;

            LatLng p = new LatLng((((double) lat / 1E5)),
                (((double) lng / 1E5)));

        return poly;

12. Update the class “MainActivity” in the file src/in/wptrafficanalyzer/locationroutedirectionmapv2/MainActivity.java

package in.wptrafficanalyzer.locationroutedirectionmapv2;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.json.JSONObject;

import android.graphics.Color;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.util.Log;
import android.view.Menu;

import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.GoogleMap.OnMapClickListener;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.android.gms.maps.model.PolylineOptions;
public class MainActivity extends FragmentActivity {

    GoogleMap map;
    ArrayList<LatLng> markerPoints;
    protected void onCreate(Bundle savedInstanceState) {

        // Initializing
        markerPoints = new ArrayList<LatLng>();

        // Getting reference to SupportMapFragment of the activity_main
        SupportMapFragment fm = (SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map);

        // Getting Map for the SupportMapFragment
        map = fm.getMap();


            // Enable MyLocation Button in the Map

            // Setting onclick event listener for the map
            map.setOnMapClickListener(new OnMapClickListener() {

                public void onMapClick(LatLng point) {

                    // Already two locations

                    // Adding new item to the ArrayList

                    // Creating MarkerOptions
                    MarkerOptions options = new MarkerOptions();

                    // Setting the position of the marker

                    * For the start location, the color of marker is GREEN and
                    * for the end location, the color of marker is RED.
                    }else if(markerPoints.size()==2){

                    // Add new marker to the Google Map Android API V2

                    // Checks, whether start and end locations are captured
                    if(markerPoints.size() >= 2){
                        LatLng origin = markerPoints.get(0);
                        LatLng dest = markerPoints.get(1);

                        // Getting URL to the Google Directions API
                        String url = getDirectionsUrl(origin, dest);

                        DownloadTask downloadTask = new DownloadTask();

                        // Start downloading json data from Google Directions API

    private String getDirectionsUrl(LatLng origin,LatLng dest){

        // Origin of route
        String str_origin = "origin="+origin.latitude+","+origin.longitude;

        // Destination of route
        String str_dest = "destination="+dest.latitude+","+dest.longitude;

        // Sensor enabled
        String sensor = "sensor=false";

        // Building the parameters to the web service
        String parameters = str_origin+"&"+str_dest+"&"+sensor;

        // Output format
        String output = "json";

        // Building the url to the web service
        String url = "https://maps.googleapis.com/maps/api/directions/"+output+"?"+parameters;

        return url;
    /** A method to download json data from url */
    private String downloadUrl(String strUrl) throws IOException{
        String data = "";
        InputStream iStream = null;
        HttpURLConnection urlConnection = null;
            URL url = new URL(strUrl);

            // Creating an http connection to communicate with url
            urlConnection = (HttpURLConnection) url.openConnection();

            // Connecting to url

            // Reading data from url
            iStream = urlConnection.getInputStream();

            BufferedReader br = new BufferedReader(new InputStreamReader(iStream));

            StringBuffer sb = new StringBuffer();

            String line = "";
            while( ( line = br.readLine()) != null){

            data = sb.toString();


        }catch(Exception e){
            Log.d("Exception while downloading url", e.toString());
        return data;

    // Fetches data from url passed
    private class DownloadTask extends AsyncTask<String, Void, String>{

        // Downloading data in non-ui thread
        protected String doInBackground(String... url) {

            // For storing data from web service
            String data = "";

                // Fetching the data from web service
                data = downloadUrl(url[0]);
            }catch(Exception e){
                Log.d("Background Task",e.toString());
            return data;

        // Executes in UI thread, after the execution of
        // doInBackground()
        protected void onPostExecute(String result) {

            ParserTask parserTask = new ParserTask();

            // Invokes the thread for parsing the JSON data

    /** A class to parse the Google Places in JSON format */
    private class ParserTask extends AsyncTask<String, Integer, List<List<HashMap<String,String>>> >{

        // Parsing the data in non-ui thread
        protected List<List<HashMap<String, String>>> doInBackground(String... jsonData) {

            JSONObject jObject;
            List<List<HashMap<String, String>>> routes = null;

                jObject = new JSONObject(jsonData[0]);
                DirectionsJSONParser parser = new DirectionsJSONParser();

                // Starts parsing data
                routes = parser.parse(jObject);
            }catch(Exception e){
            return routes;

        // Executes in UI thread, after the parsing process
        protected void onPostExecute(List<List<HashMap<String, String>>> result) {
            ArrayList<LatLng> points = null;
            PolylineOptions lineOptions = null;
            MarkerOptions markerOptions = new MarkerOptions();

            // Traversing through all the routes
            for(int i=0;i<result.size();i++){
                points = new ArrayList<LatLng>();
                lineOptions = new PolylineOptions();

                // Fetching i-th route
                List<HashMap<String, String>> path = result.get(i);

                // Fetching all the points in i-th route
                for(int j=0;j<path.size();j++){
                    HashMap<String,String> point = path.get(j);

                    double lat = Double.parseDouble(point.get("lat"));
                    double lng = Double.parseDouble(point.get("lng"));
                    LatLng position = new LatLng(lat, lng);


                // Adding all the points in the route to LineOptions

            // Drawing polyline in the Google Map for the i-th route

    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;

13. Update the file AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    android:versionName="1.0" >

        android:targetSdkVersion="17" />

    <uses-permission android:name="android.permission.INTERNET"/>

        android:protectionLevel="signature" />

    <uses-permission android:name="in.wptrafficanalyzer.locationroutedirectionmapv2.permission.MAPS_RECEIVE" />

    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>


        android:theme="@style/AppTheme" >
            android:label="@string/app_name" >
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />



Note :  Replace “YOUR_API_KEY” at the line 46 with the API key obtained in Step 8

14. Screenshot of the application

Showing route between two locations in Google Map Android API V2

Figure 7 : Showing route between two locations in Google Map Android API V2

15. Download Source Code

How to hire me?

I am George Mathew, working as software architect and Android app developer at wptrafficanalyzer.in

You can hire me on hourly basis or on project basis for Android applications development.

For hiring me, please mail your requirements to info@wptrafficanalyzer.in.

My other blogs

Android Knowledge Quiz

Ready to test your knowledge in Android? Take this quiz :

Tags: , , , , , ,

116 Responses to Drawing driving route directions between two locations using Google Directions in Google Map Android API V2

  1. Tien Hoang on March 14, 2013 at 11:59 am


  2. japanjot singh on March 21, 2013 at 6:11 pm

    sir thannnnnnnnnxx alot, i was looking for this tutorial from past few weeks, no one has so informative tut like yours…
    very helpful ;-)

  3. imam nur on March 22, 2013 at 11:23 pm

    very useful tutorial. but i want to ask you, how do I know distance traveled and a travel time to a destination specified by the user?

    I hope to find out information quickly.
    once again, I say many thanks. :)

  4. ken on March 22, 2013 at 11:49 pm

    hi. thanks for this tutorial. If i want calculate the shortest path. Can u help me?

  5. bharath on March 25, 2013 at 4:01 pm

    i got null pointer exception on this code…give any sollutions

  6. imran on April 4, 2013 at 11:34 am

    error at line map.setMyLocationEnabled(true); null point ecxeption what is the solution

    • george on April 4, 2013 at 11:54 am

      Please ensure that, the project is linked to Google Play Services library correctly

      • imran on April 4, 2013 at 3:21 pm

        yes it`s linked with Google Play service but showing warning + error also “Google play store missing” i found solution on other link they are installed gsm.apk ,vending.apk file on emulator it`s correct i tried but didn`t get any correct solution.

  7. FElipe Parente on April 8, 2013 at 7:58 pm

    Do you know how i can show the local traffic??

  8. Chandra sekhar on April 15, 2013 at 6:28 pm

    i want to draw route using source, way poins and destination

  9. omar on April 26, 2013 at 1:36 pm

    i changed the API key and still the map doesn’t show

    • Claire Ann on October 22, 2013 at 10:59 am

      Also here. I change my API KEY but the map doesn’t show.

  10. VIctor on April 26, 2013 at 7:46 pm

    Very easy. Congrats!

  11. Vhinesh on May 3, 2013 at 8:33 pm

    When I tried to implement this code, i get an error in following lines
    1. setContentView(R.layout.activity_main);
    R cannot be resolved to a variable

    2. SupportMapFragment fm = (SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map);

    3. getMenuInflater().inflate(R.menu.activity_main, menu);

    Please help in finding the errors and what change to be done in code to make it working,

    • george on May 3, 2013 at 9:06 pm

      Hi Vhinesh,

      Please try the following :

      => Ensure that, there are no errors in the file activity_main.xml

      => Clean and rebuild the project ( In Eclipse IDE, Project => Clean )

      => Ensure that, Android support library is added to this project ( check for the file “android-support-v4.jar” in the “libs” folder )

      • Vhinesh on May 3, 2013 at 10:31 pm

        thank you…very much sir,now i resolved the errors,but as i installed the app in my phone and try to open it is closing automatically say “unfortunately closed”…can you help me with this….thank you in advance

        • george on May 4, 2013 at 4:27 am

          Please check your logcat to get some hint on the error

          • Vhinesh on May 4, 2013 at 12:35 pm

            Hello Sir,
            I wanted to integrate your this project with the project displaying the nearby places like ATM. how do i combine both? both the projects contain same functions and classes.? Please help

          • Oussgh on June 2, 2013 at 5:36 pm

            Hello sir : Tank you very much for you’re efforts. unfortunately when i imported the project and i put the key provided by google api i run but it gives me an alert ” unfortunately LocationRouteDirectionMapv2 has stopped ” I need help please

  12. Umar Usman on May 5, 2013 at 6:20 pm

    Thanks alot for the tutorial. May God Bless you

  13. eman on May 9, 2013 at 8:22 am

    1-Failed to load map. Could not contact Google servers this error appear to me although map show from i write this code
    2-please i need (driving route) from my current location to another location

  14. eman on May 9, 2013 at 8:34 am

    please i want when determine my location and with another static latlng of another location it can route drive routr between them ,thanks in advance :)

  15. Ayşenur on May 13, 2013 at 1:27 am

    Hi, I tried to application but I have error. Error is null pointer exception.Please can u help me?

  16. siva on May 18, 2013 at 10:27 am

    please give me the source code for driving route from current location to given input city name

  17. Daniel on May 21, 2013 at 5:38 pm

    Awesome. It works perfectly. The next what i want to do is create some progress bar while information is proccessing (it did relatively fast :D ).

    Thank you for share.

  18. Devendar on May 21, 2013 at 7:05 pm

    Is this code works on 2.3.3 android version . i tried it but showing layoutinflater error and classnotfound exception showing please help me on this


  19. akbar on May 24, 2013 at 4:24 pm

    Good Evening, I have tried the app “Drawing route driving directions between two locations using Google Directions in Android Google Map API V2″ and succeed. I would like to combine with Hill Climbing method to search the nearest distance. whether it can be implemented? I’ve tried but still confused combine between this app n Hill climbing method. thank you

  20. Javed on May 29, 2013 at 2:11 pm

    Great…! can i use this source code APK file in my 2.3.6 api Android Samsung mobile phone.?

    • Javed on May 29, 2013 at 4:41 pm

      I got force to close message in my android phone. please help me to solve this prob.

  21. Oussgh on June 2, 2013 at 10:29 pm

    Tank you very much for you’re efforts. unfortunately when i imported the project and i put the key provided by google api i run but it gives me an alert ” unfortunately LocationRouteDirectionMapv2 has stopped ” I need help please

  22. jonathan on June 13, 2013 at 8:03 am

    nice tutorial, but i want to ask you, how to combine this tutorial with your tutorial “Android Geocoding – Showing User Input Location on Google Map Android API V2″ ??

    I hope to find out information quickly.
    once again, I say many thanks. :)

  23. Satyaki Mukherjee on June 25, 2013 at 6:01 pm

    Hello Sir,

    I would like to develop Map Tracker view like Open GPS Map Tracker. How can I develop this please produce one of the tutorial on the basis of that.


  24. Hassaan on July 1, 2013 at 2:07 pm

    I want to mark my second position as current to dram route from the location where i first clicked upto the current location where i am present, how can i?

  25. Vijay on July 12, 2013 at 2:03 pm

    I have tried this tutorial to run on EMULATOR,this is working well till displaying two MARKERS on MAP where I have clicked but this is not not showing any route between these two MARKERS and then getting crashed.
    Can you please help me out.

  26. Khayyam on July 15, 2013 at 3:13 pm

    I did what you say in this tutorial, but got some problem about “import com.google.android.gms.maps.”
    Could you help me, please!

  27. li gang on July 26, 2013 at 2:02 pm

    Thanks for this great tutorial, however, just as other people said, there is no any route between the two markers (origin and destination).I used Log.i to debug, found result.size()=0 at class ParserTask. Maybe there is something wrong when parsing JSON format.
    Looking forward to your reply.

    • li gang on July 26, 2013 at 2:49 pm

      Sorry, this tutorial has no fault because I tested the web version, there is no route either.

    • george on July 26, 2013 at 2:55 pm

      Please check you are getting a valid json data containing direction details from the function downloadUrl().

  28. richin on July 30, 2013 at 4:11 pm

    please help me in obtaining the route travelled on maps,using gps becoz i am doing an app on tracking gps enabled vehicles from diffrent locations.. pls do help..it is urgent

  29. santhanam on August 3, 2013 at 12:18 pm

    you are an excellent programmer.. thank you very much..

  30. bott on August 5, 2013 at 9:27 pm

    I use part of you code and work fine! Really thanks!!

  31. pilah on August 13, 2013 at 6:19 pm

    Dear george

    Thank you for your tutorial is very interesting
    when I execute your project I have these two errors:
    The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
    Failed to load map. Error contacting Google servers. This is probably an authentication issue (but could be due to network errors).

    Thank you for your help
    Best regards

  32. mr Cuong on August 27, 2013 at 1:24 pm

    hi you,
    Thanks u so much for your code

  33. Ralph on September 5, 2013 at 4:39 pm

    Take a look at the Google Maps Android API utility library[1]
    There is also a (better) Poly decoding and encoding tool

    [1] … http://googlemaps.github.io/android-maps-utils/

  34. Imron RM on October 14, 2013 at 9:29 am

    Hi, george can you help me?
    why did i get force close when i try to get direction
    i use samsung galaxy Y duos to run the project
    And Thanks, your tutorials are very good

  35. Ankur Shrivastava on October 26, 2013 at 9:11 pm

    Hi, i want to knw if it is possible to get google auto complete api key with out registering website address…. if yes then it would be great if you could explain that in detail.. thanks in advance

  36. kandarp on November 14, 2013 at 1:03 am

    hi sir nice tutorial but , i need some code in which user can input both places name and then can find route , not by touch . i want to get input places from user through edit txt

  37. Prushni on November 26, 2013 at 5:03 pm

    Very nice tutorial. i need some code in which user can input destination place name and then can find route , not by touch . i want to get input place from user through edit txt

  38. JITHINRAJ on December 17, 2013 at 6:15 pm

    very nice tutorial , its working perfectly.. Thanks a lot..

    • fwff on May 26, 2016 at 1:29 pm


  39. Arunraj on January 21, 2014 at 1:28 pm

    hello sir,
    When I use the apk file in Samsung 2.3.6 version.I got force to close message in my android phone. please help me to solve this problm.

    • chandu on January 21, 2014 at 4:56 pm

      update maps app in your phone as well play services it will fix the issue

  40. Chloeingelical on January 27, 2014 at 11:00 pm

    Hi,may I know how can I get turn by turn direction using text view? For example turn left at 50 m, turn right at 100 m to get to the destination? Appreciate if anyone can help me :) Thank you.

  41. tom on January 29, 2014 at 2:19 pm

    this is shortest path? it is Djikstra or greedy method?

  42. sriram on January 30, 2014 at 11:31 am

    Hi I tried this tutorial but the app is getting closed in android device. Please help me to resolve this.

  43. maniraj on January 31, 2014 at 11:28 pm

    Nice tutorial.

    Please guide me
    a) how can i get the latitude and longitude from the current location far 100 meters to find out the curve of road or turn found and find the angles.

    thanks in advance

  44. souvik samanta on February 9, 2014 at 1:21 pm

    sir i tried google android api to draw directions between two points. its going well. i want to know how the show the direction in text form i.e like this “take right 100m, take left t0 200m”. please help me out. if possible send the code for doing this.

    reply ASAP.

  45. Irfan on February 16, 2014 at 1:54 pm

    Thanks for the nice tutorial

    How can I move my current pointer on the direction route, So that i can have navigation.

    Thanks in Advance.

  46. Veach Pisal on February 20, 2014 at 3:43 pm

    Dear Admin,
    What do I need to change in the code if I want to draw line from a current location(setMyLocationEnable) to a marker by just click on the marker?

    Thanks in advance for your reply!

  47. liezl on February 20, 2014 at 7:45 pm

    why did i got error in this statement ” SupportMapFragment fm = (SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map);” My error is “map is not a field”

  48. Tássio Caique on February 27, 2014 at 1:13 am

    Thx for the tuts.
    I’m getting a NullPointerException, because the value of result size is 0. I verify the log and the json output is got correctally. Which can be my problem? (The problem isn’t on the Parser). Thanks in advance.

  49. kushal on February 28, 2014 at 5:55 pm

    hey Nice Tutorial but i want to change route to drag marker when i change route that PolyLine will not remove from google map any idea thannk

  50. Razvan on May 26, 2014 at 2:20 pm

    Hy there , is there an posibility to get all intersections from a route?

  51. Jeeva on August 25, 2014 at 11:51 am

    Dear friends,

    I want to change the polyline color in some meter,
    Pls any one do the need full.


  52. Bunny on September 2, 2014 at 11:26 am

    Hello. Nice tutorial. Can you please tell how can we display the traffic information on the routes ?

  53. saifullah on September 10, 2014 at 3:06 pm

    pls draw the class diagram how it works

  54. Vishnu on September 24, 2014 at 5:51 pm

    Thanks for the tutorial, I need one more help that how can I make Geofencing to track that I am following correct route and I will get a alert If I am on wrong route.

  55. bahgat on October 13, 2014 at 12:19 am

    very very nice tutorial , its working perfectly. Thanks a lot……

  56. nizam on December 2, 2014 at 2:12 pm

    Hi sir your example so good but i got error of inflating fragment in logcat pls help i stuck here

  57. DEv on December 5, 2014 at 3:24 pm

    if i select destination that is too far from the start location the map is not zooming out to include both markers.How will we do that.Can you tell me please

  58. Neha Singh on December 27, 2014 at 5:18 pm


    Thanks for the tutorial.

    I have a code to markers to a set of locations on google map v2.

    And I need to add a feature where driving route will be shown when u click on any one marker from source marker.

    Could you please add a tutorial for that?

  59. victor on February 13, 2015 at 6:47 am

    i want a idea for make a app for public transportation. Is for 30 bus. each bus have one route. i want to know how i can if the user want go to some direction what bus or buses he has to take for go to that direction.

  60. Kushal Gandhi on March 10, 2015 at 4:48 pm

    Thank you sir for you tutorial
    This is very good example for Google Maps Direction APIs use

    Thank you

  61. oubaida on March 13, 2015 at 1:17 pm

    Thank you sir for you tutorial
    How list all route from my location to destination in Google Maps Android

  62. Tom on March 20, 2015 at 12:19 am

    hi sir, great tutorial by the way. i followed all the codes and no errors at all but when i run it then try to tap in the map i got the first position then when i tap again my app crashes . in what part did i got wrong ? please help. i run it with my device Gingerbread OS. thanks

  63. Viren on March 21, 2015 at 3:10 pm

    hello sir!
    really helpfull tutorial..
    Now, I am doing the same but taking user input as entering location.
    for that i am using place api.. which returns lat and longitude of both to and from and the i pass it within this..

    i am merging ol.. yess.. i am getting the result but kinda conflict is there can u link me any example of doing the same.

  64. ashika on March 31, 2015 at 3:01 pm

    I want to highlight different alternatives between two places.
    This program just highlights one route.

  65. usman on April 4, 2015 at 12:55 am

    thanks works perfect
    1)i want shortest path like if i search medicals the medicals near me appear in the form of marker (i already done this) after that the shortest path is selected and show the distance and polyline
    2) i want all medical stores show in a list and order by shortest distance
    plz help

  66. abhishek on April 4, 2015 at 10:27 am

    Hi George
    thanks for this code.
    But plz guide me How to get shortest route from my location to more then one location.

  67. abhishek on April 14, 2015 at 11:17 pm

    Hi George,
    Thank you for this helpful code But plz tell me how to add third marker in this code plz help me.

  68. Ruto Martin on April 20, 2015 at 12:42 pm

    thank you for this, it a great bit of code.
    i want to know if there is a way to add traffic information to the app gotten from a user. like if i state there is traffic on this route then the next user on the same route will be given a different direction.
    any information will be helpful.

  69. Ruto Martin on April 20, 2015 at 12:46 pm

    thank you very much for this, it a great bit of code.
    i want to know if there is a way to add traffic information to the app gotten from a user. like if i state there is traffic on this route then the next user on the same route will be given a different direction.
    any information will be helpful.

  70. zahid on April 24, 2015 at 1:52 pm

    helo… i follow ur tutrial … but map could not load … please help me … i got white screen zoom in and our button there but map is not loading…. give some tip

  71. Luong on May 8, 2015 at 3:17 pm

    Thank you so much! It is very helpful

  72. Tahmid on May 9, 2015 at 3:12 am

    Thank u so much! Got success at first attempt.. .

  73. Afir on May 11, 2015 at 8:13 pm

    thank youuuu, it’s very useful

  74. hari on May 18, 2015 at 1:56 pm

    Hi sir,
    Your codes are working but i have to pass the origin and destination latlong value manually without touching the map i have to show the path when the activity starts.

  75. Santosh Sali on May 29, 2015 at 12:17 pm

    thanks nice and very helpful post for me :-)

  76. chaimaa on May 29, 2015 at 5:50 pm

    Thank you so much ! it works perfectly :)

  77. simao on June 1, 2015 at 4:35 am

    Hi George I want to do real-time tracking Gps Please can you help me thank you very much .

  78. Mohamed Elkady on June 11, 2015 at 3:14 am

    great tutorial from a great developer,
    in my case, i need to develop an app that can help blinds to go from place A to place B using voice instructions. how can i do this using your tutorial
    thanks in advance. :D

  79. abul on June 25, 2015 at 11:51 am

    Thank you GEORGE MATHEW for Tutorial
    very help me

  80. Sanjay on July 2, 2015 at 6:38 pm

    Sir I want to add markers not on touch but on given longitude and latitude
    Also this algo is taking too much time to calculate path

  81. Jitender on July 8, 2015 at 8:47 pm

    Thanks for the code. But this code by default draw the route according to the “right lane”.But i live in a country where the drive lane is left. Please suggest the code changes for this .


  82. vijay on July 18, 2015 at 10:50 pm

    Hi, is it possible to get alternative route ..as it is possible in javascript google map api v3….? pls reply

  83. Anum on July 23, 2015 at 2:21 pm

    thanks this is a great tutorial.
    I want to put first marker as my current source location that is first appeared on map in blue dot.
    means 1st marker will be automatically appear on current location which is in blue dot.

    how can i do that in this code?

  84. Suman Ghimire on July 29, 2015 at 8:53 pm

    Does it give the shortest distance between the two points?
    Is it possible to find the optimum distance between 3 points through GoogleMaps API-for delivery purposes….
    I look forward to hear from you.

  85. yusuke on August 9, 2015 at 9:12 pm

    can i use this in android studio?

  86. Tarique shamsi on August 14, 2015 at 4:34 pm

    Sir your code for google place api for android map is very useful. can i use this code with google place api autocomplete code for showing the line between two marker.how is it possible???plz reply

  87. Vijay sagaram on September 3, 2015 at 4:23 pm

    Hi, I want to find a location which is in between two locations.how can you achieve this….Plz let me know…

  88. Ragnar on October 2, 2015 at 10:17 am

    Hello, I dont seem to get this part:
    why is it needed in the permission, should I also use it?

    hope to hear from you.

  89. Bruna on October 19, 2015 at 6:03 am

    This code helped me a lot, guy! :D

  90. sam on October 23, 2015 at 4:48 am

    Is it possible to save the JSONObject to be parsed on a server and then retrieve it later to draw the route at a later time?

  91. Jefferson Vinluan on February 5, 2016 at 10:14 pm

    Hello sir! thank you so much for your tutorial it’s very helpful to my thesis about vehicle tracking system. Anyways, i would like to ask if this path being created is the shortest path? or kindly pls explain the algorithm you used. Thank you again sir :)

  92. mal on February 6, 2016 at 6:06 pm

    this example draws on path between two points. What if we want to draw all possible paths between two points.How can that be done?

  93. Pratibha on February 11, 2016 at 11:40 am


    Thanks.. very nice example.. working great.

  94. Ala' Hashesh on February 13, 2016 at 7:51 pm

    Thank you for this.
    one note though:
    In the MainActivity line 252


    This line should be inside the loop.

    Again many thanks for this :D :D :D

  95. Sughan Pandita on February 28, 2016 at 8:52 am

    Getting problem in getMap() showing this method deprecated.Please help

  96. raseena on March 6, 2016 at 10:53 pm

    i want to take source as my current location and ask detination to user.the route between these two place shold be shown and travell time and distance also sholud be shown..what can i do ?

  97. Durga on March 24, 2016 at 10:14 pm

    Can you please tell me what I should do to draw multiple routes between multiple locations? Its pretty urgent.

  98. Durga on March 24, 2016 at 10:16 pm

    Should I make changes regarding url and downloadtask statements in onCreate function to mark multiple routes?

Leave a Reply to george Cancel reply

Your email address will not be published. Required fields are marked *

Be friend at g+

Subscribe for Lastest Updates

FBFPowered by ®Google Feedburner