Guide: Google Maps V2 for Android: Draw Driving Direction on Map:

This is again one of those popular questions that I stumble upon, I already gave here an
answer for this one, but I decided to put it in here anyways as a post. So let get started.
First of all if you are not familiar with Google’s new Maps API, I suggest you to first of all read
this post: Google Maps API V2 Key to get your own API key which is required to
integrate Google maps in your application. Next follow this post: Google Maps API V2
to actually integrate Google Maps in your application.

If you already have a map integrated in your application and you want to add driving navigation
to it, you came to the right place. Here I will present you the code that will allow you to paint a line
(Polyline object on your map) to show the directions from point A to B. But first I would like
to point your to this quote:

Google Maps/Google Earth APIs Terms of Service

  Last updated: May 27, 2009
...
10. License Restrictions. Except as expressly permitted under the Terms, or unless you
have received prior written authorization from Google (or, as applicable, from the
provider of particular Content), Google's licenses above are subject to your adherence
to all of the restrictions below. Except as explicitly permitted in Section 7 or the
Maps APIs Documentation, you must not (nor may you permit anyone else to):
...
10.9 use the Service or Content with any products, systems, or applications for or in
connection with:

(a) real time navigation or route guidance, including but not limited to turn-by-turn
route guidance that is synchronized to the position of a user's sensor-enabled device;

and may be disabled for certain apps (somehow, at least on Android)... FromGeocode
scraping in .NET conversation:
This is not allowed by the API terms of use. You should not scrape Google Maps to
generate geocodes. We will block services that do automated queries of our servers.

Bret Taylor
Product Manager, Google Maps

I might be mistaken but from my understanding of this quote Google does not allow to show
driving navigation using Google Maps. Now that we covered that I will show you how you can
paint on the map.

1. So lets start with the GMapV2Direction class, this class is responsible to
make a request to Google Directions API and get the navigation instruction for 2 LatLng points:

public class GMapV2Direction {
    public final static String MODE_DRIVING = "driving";
    public final static String MODE_WALKING = "walking";

    public GMapV2Direction() { }

    public Document getDocument(LatLng start, LatLng end, String mode) {
        String url = "http://maps.googleapis.com/maps/api/directions/xml?"
                + "origin=" + start.latitude + "," + start.longitude
                + "&destination=" + end.latitude + "," + end.longitude
                + "&sensor=false&units=metric&mode=" + mode;

        try {
            HttpClient httpClient = new DefaultHttpClient();
            HttpContext localContext = new BasicHttpContext();
            HttpPost httpPost = new HttpPost(url);
            HttpResponse response = httpClient.execute(httpPost, localContext);
            InputStream in = response.getEntity().getContent();
            DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
            Document doc = builder.parse(in);
            return doc;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public String getDurationText (Document doc) {
        NodeList nl1 = doc.getElementsByTagName("duration");
        Node node1 = nl1.item(0);
        NodeList nl2 = node1.getChildNodes();
        Node node2 = nl2.item(getNodeIndex(nl2, "text"));
        Log.i("DurationText", node2.getTextContent());
        return node2.getTextContent();
    }

    public int getDurationValue (Document doc) {
        NodeList nl1 = doc.getElementsByTagName("duration");
        Node node1 = nl1.item(0);
        NodeList nl2 = node1.getChildNodes();
        Node node2 = nl2.item(getNodeIndex(nl2, "value"));
        Log.i("DurationValue", node2.getTextContent());
        return Integer.parseInt(node2.getTextContent());
    }

    public String getDistanceText (Document doc) {
        NodeList nl1 = doc.getElementsByTagName("distance");
        Node node1 = nl1.item(0);
        NodeList nl2 = node1.getChildNodes();
        Node node2 = nl2.item(getNodeIndex(nl2, "text"));
        Log.i("DistanceText", node2.getTextContent());
        return node2.getTextContent();
    }

    public int getDistanceValue (Document doc) {
        NodeList nl1 = doc.getElementsByTagName("distance");
        Node node1 = nl1.item(0);
        NodeList nl2 = node1.getChildNodes();
        Node node2 = nl2.item(getNodeIndex(nl2, "value"));
        Log.i("DistanceValue", node2.getTextContent());
        return Integer.parseInt(node2.getTextContent());
    }

    public String getStartAddress (Document doc) {
        NodeList nl1 = doc.getElementsByTagName("start_address");
        Node node1 = nl1.item(0);
        Log.i("StartAddress", node1.getTextContent());
        return node1.getTextContent();
    }

    public String getEndAddress (Document doc) {
        NodeList nl1 = doc.getElementsByTagName("end_address");
        Node node1 = nl1.item(0);
        Log.i("StartAddress", node1.getTextContent());
        return node1.getTextContent();
    }

    public String getCopyRights (Document doc) {
        NodeList nl1 = doc.getElementsByTagName("copyrights");
        Node node1 = nl1.item(0);
        Log.i("CopyRights", node1.getTextContent());
        return node1.getTextContent();
    }

    public ArrayList getDirection (Document doc) {
        NodeList nl1, nl2, nl3;
        ArrayList listGeopoints = new ArrayList();
        nl1 = doc.getElementsByTagName("step");
        if (nl1.getLength() > 0) {
            for (int i = 0; i < nl1.getLength(); i++) {
                Node node1 = nl1.item(i);
                nl2 = node1.getChildNodes();

                Node locationNode = nl2.item(getNodeIndex(nl2, "start_location"));
                nl3 = locationNode.getChildNodes();
                Node latNode = nl3.item(getNodeIndex(nl3, "lat"));
                double lat = Double.parseDouble(latNode.getTextContent());
                Node lngNode = nl3.item(getNodeIndex(nl3, "lng"));
                double lng = Double.parseDouble(lngNode.getTextContent());
                listGeopoints.add(new LatLng(lat, lng));

                locationNode = nl2.item(getNodeIndex(nl2, "polyline"));
                nl3 = locationNode.getChildNodes();
                latNode = nl3.item(getNodeIndex(nl3, "points"));
                ArrayList arr = decodePoly(latNode.getTextContent());
                for(int j = 0 ; j < arr.size() ; j++) {
                    listGeopoints.add(new LatLng(arr.get(j).latitude, arr.get(j).longitude));
                }

                locationNode = nl2.item(getNodeIndex(nl2, "end_location"));
                nl3 = locationNode.getChildNodes();
                latNode = nl3.item(getNodeIndex(nl3, "lat"));
                lat = Double.parseDouble(latNode.getTextContent());
                lngNode = nl3.item(getNodeIndex(nl3, "lng"));
                lng = Double.parseDouble(lngNode.getTextContent());
                listGeopoints.add(new LatLng(lat, lng));
            }
        }

        return listGeopoints;
    }

    private int getNodeIndex(NodeList nl, String nodename) {
        for(int i = 0 ; i < nl.getLength() ; i++) {
            if(nl.item(i).getNodeName().equals(nodename))
                return i;
        }
        return -1;
    }

    private ArrayList decodePoly(String encoded) {
        ArrayList poly = new ArrayList();
        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 position = new LatLng((double) lat / 1E5, (double) lng / 1E5);
            poly.add(position);
        }
        return poly;
    }
}

2. Because finding the desired route is a potentially long running task,
we need to place this in a AsyncTask in order to avoid blocking the UI-Thread.
So we are going to create the following GetDirectionsAsyncTask:

public class GetDirectionsAsyncTask extends AsyncTask<Map<String, String>, Object, ArrayList>
{
    public static final String USER_CURRENT_LAT = "user_current_lat";
    public static final String USER_CURRENT_LONG = "user_current_long";
    public static final String DESTINATION_LAT = "destination_lat";
    public static final String DESTINATION_LONG = "destination_long";
    public static final String DIRECTIONS_MODE = "directions_mode";
    private MapFragmentActivity activity;
    private Exception exception;
    private ProgressDialog progressDialog;

    public GetDirectionsAsyncTask(MapFragmentActivity activity)
    {
        super();
        this.activity = activity;
    }

    public void onPreExecute()
    {
        progressDialog = new ProgressDialog(activity);
        progressDialog.setMessage("Calculating directions");
        progressDialog.show();
    }

    @Override
    public void onPostExecute(ArrayList result)
    {
        progressDialog.dismiss();
        if (exception == null)
        {
            activity.handleGetDirectionsResult(result);
        }
        else
        {
            processException();
        }
    }

    @Override
    protected ArrayList doInBackground(Map<String, String>... params)
    {
        Map<String, String> paramMap = params[0];
        try
        {
            LatLng fromPosition = new LatLng(Double.valueOf(paramMap.get(USER_CURRENT_LAT)) , Double.valueOf(paramMap.get(USER_CURRENT_LONG)));
            LatLng toPosition = new LatLng(Double.valueOf(paramMap.get(DESTINATION_LAT)) , Double.valueOf(paramMap.get(DESTINATION_LONG)));
            GMapV2Direction md = new GMapV2Direction();
            Document doc = md.getDocument(fromPosition, toPosition, paramMap.get(DIRECTIONS_MODE));
            ArrayList directionPoints = md.getDirection(doc);
            return directionPoints;
        }
        catch (Exception e)
        {
            exception = e;
            return null;
        }
    }

    private void processException()
    {
        Toast.makeText(activity, activity.getString(R.string.error_when_retrieving_data), 3000).show();
    }
}

3. No we would like to use this AsyncTask to find the road direction from one
location to another. To make the usage of this AsyncTask a little bit more convenient I have
created the following findDirections method in my MapFragmentActivity:

public void findDirections(double fromPositionDoubleLat, double fromPositionDoubleLong, double toPositionDoubleLat, double toPositionDoubleLong, String mode)
{
    Map<String, String> map = new HashMap<String, String>();
    map.put(GetDirectionsAsyncTask.USER_CURRENT_LAT, String.valueOf(fromPositionDoubleLat));
    map.put(GetDirectionsAsyncTask.USER_CURRENT_LONG, String.valueOf(fromPositionDoubleLong));
    map.put(GetDirectionsAsyncTask.DESTINATION_LAT, String.valueOf(toPositionDoubleLat));
    map.put(GetDirectionsAsyncTask.DESTINATION_LONG, String.valueOf(toPositionDoubleLong));
    map.put(GetDirectionsAsyncTask.DIRECTIONS_MODE, mode);

    GetDirectionsAsyncTask asyncTask = new GetDirectionsAsyncTask(this);
    asyncTask.execute(map);
}

What I’m doing here is creating a HashMap with the needed coordinates
(Start Lat and Long, End Lat and Long), Passing them to the AsyncTask and executing it.

4. Next, we will create the following handleGetDirectionsResult method,
to handle the AsyncTask result and to actually paint the directions Polyline on the map.

public void handleGetDirectionsResult(ArrayList directionPoints)
{
    Polyline newPolyline;
    GoogleMap mMap = ((SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
    PolylineOptions rectLine = new PolylineOptions().width(3).color(Color.BLUE);
    for(int i = 0 ; i < directionPoints.size() ; i++)
    {
        rectLine.add(directionPoints.get(i));
    }
    newPolyline = mMap.addPolyline(rectLine);
}

5. Finally to get the direction we need to run the findDirections method
with the desired locations in code like this:

findDirections(SGTasksListAppObj.getInstance().currentUserLocation.getLatitude(),
SGTasksListAppObj.getInstance().currentUserLocation.getLongitude(),
clickMarkerLatLng.latitude, clickMarkerLatLng.longitude, GMapV2Direction.MODE_DRIVING );

The final result should look something like that:

direction_blue

As you see a blue directions line is drown on the map, for showing the way you need to
go for your destination. And that’s it, you are finished.

6. UPDATE: Due to many requests I have created a small Android project that
demonstrates the usage of this code. You can download this project from here.
The project show how to navigate from Amsterdam to Paris or to Frankfurt, just
remember to add your Google Maps API V2 Key in the manifest file.

Enjoy and stay tuned.

58 Responses to this entry

  • Raja Rajan Says:

    thank you very much…It’s very simple and useful example..

    Posted on July 3rd, 2013 at 1:47 pm Reply | Quote
  • Emil Adjiev Says:

    @Raja Rajan you welcome. I’m glad you found it useful.

    Posted on July 19th, 2013 at 6:08 pm Reply | Quote
  • Pearly Says:

    Hi will it be possible if you could give us the full codes for the project? Greatly appreciated! :)

    Posted on July 21st, 2013 at 10:16 pm Reply | Quote
  • Emil Adjiev Says:

    @Pearly currently this code is part of a bigger work project that I can’t post here. I will try to take some time and build a new project with only this code in the near future and provide it here for the users.

    Posted on July 23rd, 2013 at 4:59 pm Reply | Quote
  • sourabh Says:

    Thanks for code. I am having 2 error in this code.

    1. progressDialog = DialogUtils.createProgressDialog(activity,activity.getString(R.string.get_data_dialog_message));
    — DialogUtils is undefined. Is there any pakage I need to download and import or need to create manually(any code anywhere)?

    2. GoogleMap mMap = ((SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
    — getSupportFragmentManager() is undefined. Although I have already import these 2 reference :
    import com.google.android.gms.maps.MapFragment;
    import com.google.android.gms.maps.SupportMapFragment;

    Please help!!!

    Posted on July 26th, 2013 at 10:44 am Reply | Quote
  • Emil Adjiev Says:

    @sourabh hi, regarding you problems:
    1. DialogUtils is a class I created that is responsible to show different kinds of dialogs in my
    application. You can just remove those lines from code, or create your own dialog
    (I will remove it from the guide as well, forgot to do that).

    2. Regarding the SupportMapFragment class, you are doing it the wrong way. you need not to import those files in you activity class, but to refrence the Google-play-services library the way it described in the following guide: Google Maps API V2 Guide in step 3.

    Posted on July 26th, 2013 at 2:44 pm Reply | Quote
  • sourabh Says:

    @Emil : It is solved when I extends FragmentActivity instead of Activity.

    Posted on July 26th, 2013 at 6:52 pm Reply | Quote
  • Emil Adjiev Says:

    @sourabh great news, I’m glad you got it figured out.

    Posted on July 28th, 2013 at 7:16 am Reply | Quote
  • sourabh Says:

    Thanks Alot!!! it really works!! :) :)

    Posted on August 7th, 2013 at 9:43 pm Reply | Quote
  • Tugsuu Says:

    Thank you, it’s very useful :)

    Posted on September 21st, 2013 at 12:26 pm Reply | Quote
  • Mohan Says:

    HI it’s awesome stuff ! is it possible to get the live navigation based on the vehicles movement ? I need it for a project ! thanks in advance ! :) :)

    Posted on September 23rd, 2013 at 9:30 am Reply | Quote
  • Emil Adjiev Says:

    @Mohan yes, of course it possible to get live navigation. You will have to implement a LocationListener to get your location updates and then repaint the navigation Polyline based on those updates.

    Posted on September 23rd, 2013 at 9:52 am Reply | Quote
  • Jacks Says:

    Hi i have problem how to make direction when i click marker, i want to make direction from my location to marker that i clicked.

    Posted on October 3rd, 2013 at 8:36 pm Reply | Quote
  • Jacks Says:

    i still cant figured out how to make this problem, would you mind to share full code?

    Posted on October 3rd, 2013 at 9:05 pm Reply | Quote
  • Kabir Says:

    Getting error on this line at GMapV2Direction ” longitude cannot be resolved”
    listGeopoints.add(new LatLng(arr.get(j).latitude, arr.get(j).longitude));
    What should do now

    Posted on October 7th, 2013 at 8:45 am Reply | Quote
  • Emil Adjiev Says:

    @Jacks Hi, I can’t post the full currently because this is part of a work project I have been working on. But you can post a question in Stackoverflow, post here a link and I will try to help you.

    Posted on October 7th, 2013 at 10:30 am Reply | Quote
  • Emil Adjiev Says:

    @Kabir Hi, I didn’t understood what exactly is your problem, could you provide more information. Or better, please open an informative question on Stackoverflow and post here a link and I will try to help you.

    Posted on October 7th, 2013 at 10:35 am Reply | Quote
  • Kabir Says:

    @Kabir Hi, I didn’t understood what exactly is your problem, could you provide more information. Or better, please open an informative question on Stackoverflow and post here a link and I will try to help you.

    http://stackoverflow.com/questions/19219688/getting-error-on-line-drawing-with-google-map-v2-using-gmapv2direction

    I am just getting error on this latitued and longitued

    listGeopoints.add(new LatLng(arr.get(j).latitude, arr.get(j).longitude));

    It says “latitude cannot be resolved or its not a field” & “longitudecannot be resolved or its not a field”
    If i press ctrl+space after arr.get(j). it shows no suggestion like latitude/longitude
    u understand?

    Posted on October 7th, 2013 at 11:08 am Reply | Quote
  • Emil Adjiev Says:

    @Kabir so if I understand correctly your objects inside the array don’t have latitude/longitude fields. I would guess that this is the reason you can’t get data from those fields.

    Posted on October 7th, 2013 at 11:33 am Reply | Quote
  • Jacks Says:

    Hi emil, i wanted to make a destination marker on another mareker based on latitutde and logitute.

    so when i click another marker then the path will routing to place with marker.
    like this
    Name lat longi
    marker place one (-6.12334, 11.0123123)
    marker place two (-6.32244, 12.213423)
    marker place three(-5.8212, 10.86435)

    nah, when marker place one clicked then directions will showing from my locations ( current position) to marker place one.

    i can make direcection, but when using im tapping marker(based on longitude and latitude) i cant tapping that marker. i must tapping near the marker to make a direction

    this is the code emil http://wptrafficanalyzer.in/blog/driving-route-from-my-location-to-destination-in-google-maps-android-api-v2/

    Posted on October 8th, 2013 at 3:02 pm Reply | Quote
  • Jacks Says:

    Hi emil i have this problem, this is my question from stackoverflow
    http://stackoverflow.com/questions/19096040/android-map-infowindow-on-click-marker/19112276?noredirect=1#19112276

    Posted on October 8th, 2013 at 8:13 pm Reply | Quote
  • nisansi Says:

    @Kabir

    I got the same problem.
    instead of [java]ArrayList[/java] put [java]ArrayList<LatLng>[/java]
    Then my problem solved :D

    Posted on November 7th, 2013 at 3:34 am Reply | Quote
  • nisansi Says:

    @ Emil
    Thanks a lot. This worked as a charm. But I want to get the co-ordinates of the waypoints (only the turning points) along the drawn path. because i want to calculate the directions between those turning points. :D

    Posted on November 7th, 2013 at 8:10 am Reply | Quote
  • ultraman Says:

    In MapFragmentActivity, findDirections(SGTasksListAppObj.getInstance().currentUserLocation.getLatitude(),
    SGTasksListAppObj.getInstance().currentUserLocation.getLongitude(),
    clickMarkerLatLng.latitude, clickMarkerLatLng.longitude, GMapV2Direction.MODE_DRIVING );

    I detect two error that SGTasksListAppObj, clickMarkerLatLng

    what does mean? SGtasksListAppObj, clickMarkerLatLng

    Posted on November 11th, 2013 at 12:33 pm Reply | Quote
  • Emil Adjiev Says:

    @ultraman Hey, the SGTasksListAppObj is my Application class in which I store the clickMarkerLatLng which is basically a LatLng object on the currently clicked marker, I store it there because I needed to access it’s data from other Activities.

    Posted on November 12th, 2013 at 7:32 pm Reply | Quote
  • bala Says:

    What is MapFragmentActivity?Is it the name of the main Activity file ?

    Posted on November 14th, 2013 at 10:07 am Reply | Quote
  • Emil Adjiev Says:

    @bala Yes exactly, This is my Activity that contains the MapFragment on which I paint the direction.
    In your case it can be any other Activity that holds this fragment.

    Posted on November 14th, 2013 at 12:37 pm Reply | Quote
  • bala Says:

    Hey , I figured that out myself. I have a question. How to get the actual directions in text point-by-point?

    Posted on November 14th, 2013 at 1:52 pm Reply | Quote
  • Exequiel Says:

    Hello, my name is exequiel, I’m from chile. I need to do this in my project, but it throws errors, you could send this project to my mail? My main mistake was findDirections (SGTasksListAppObj.getInstance (). CurrentUserLocation.getLatitude (),
    SGTasksListAppObj.getInstance (). CurrentUserLocation.getLongitude ()
    clickMarkerLatLng.latitude, clickMarkerLatLng.longitude, GMapV2Direction.MODE_DRIVING);

    My email is ex.espinoza @ alumnos.duoc.cl, if you can send me this project would be very grateful and would help me a lot in my studies

    Posted on November 15th, 2013 at 3:20 am Reply | Quote
  • Emil Adjiev Says:

    @Exequiel Hey, I have added a small project in section 6 that you can download.

    Posted on November 17th, 2013 at 9:59 pm Reply | Quote
  • 나그네 Says:

    thank you ! thank you! and thank you!

    Posted on November 19th, 2013 at 5:51 pm Reply | Quote
  • Edzel Says:

    i tried the project that you created but it gives me an error.

    [java]
    Caused by: java.lang.IllegalStateException: The meta-data tag in your app’s AndroidManifest.xml does not have the right value. Expected 4030500 but found 0. You must have the following declaration within the element:
    [/java]

    Posted on November 20th, 2013 at 10:21 am Reply | Quote
  • Emil Adjiev Says:

    @Edzel As the error suggests, replace this meta-data:
    [java]
    <meta-data
    android:name="com.google.android.gms.version"
    android:value="@integer/google_play_services_version" />
    [/java]

    with this:
    [java]
    <meta-data
    android:name="com.google.android.gms.version"
    android:value= "4030500" />
    [/java]

    Posted on November 20th, 2013 at 6:16 pm Reply | Quote
  • Ainunnjb Says:

    Hi Sir,

    I get problem when i click navigate button , not show any maps , just dialog calculation process then not any direction.
    what’s wrong with my code????

    Posted on December 1st, 2013 at 4:46 am Reply | Quote
  • Emil Adjiev Says:

    @Ainunnjb Hey, if you are using the provided code then as said in the post: “just
    remember to add your Google Maps API V2 Key in the manifest file.” , So you need to produce an API key to get it started.

    Posted on December 1st, 2013 at 5:34 pm Reply | Quote
  • Ainunnjb Says:

    @Emil Adjiev i already produce my API key and add to manifest file but no map and direction
    this is my manifest file :

    Sir , i tried your tutorial creating your google map application and success and i tried this but not success.
    i want to ask you about the key , if i make other application i must make new key or i can use previous key?

    I’m Newbie in this.
    thank you.

    Posted on December 1st, 2013 at 9:52 pm Reply | Quote
  • Ainunnjb Says:

    This is my manifest file :

    Posted on December 1st, 2013 at 9:54 pm Reply | Quote
  • Ainunnjb Says:

    This is my manifest file :
    android:name=”com.google.android.maps.v2.API_KEY”
    android:value=”AIzaSyAkxQHbUnOUTQKhHANikeGeqduS6bzappM”

    Posted on December 1st, 2013 at 9:55 pm Reply | Quote
  • Dimpy Says:

    how we can get audio tracks for all route nodes in that google map v2?

    Posted on December 11th, 2013 at 12:06 pm Reply | Quote
  • Emil Adjiev Says:

    @Dimpy Hey, Actually it’s a great question, I have no idea. If you find a way please share it with me.

    Posted on December 11th, 2013 at 11:56 pm Reply | Quote
  • kishore Says:

    Hi emi’s
    very nice tutorial very much useful in my project.
    All is working fine in android device like htc and micromax.
    but i found problem when my appication install in samsung and other mobile
    google map is not displaying only zoom button are displaying with grey screen
    can solve my problem…

    Posted on December 27th, 2013 at 7:42 am Reply | Quote
  • edo Says:

    Thank u very much, it’s very useful

    Posted on December 31st, 2013 at 5:34 am Reply | Quote
  • Jordan Says:

    Hey. Good day! I have a problem with this:

    [java]
    for(int j = 0 ; j &lt; arr.size() ; j++) {
    listGeopoints.add(new LatLng(arr.get(j).latitude, arr.get(j).longitude));
    };
    [/java]

    ".LATITUDE" and ".LONGITUDE" are not working.

    it says that it cannot be resolved or is not a field.

    can you help me?

    Posted on February 4th, 2014 at 4:56 pm Reply | Quote
  • Emil Adjiev Says:

    @Jordan, I have a strange feeling that you have made the wrong imports.

    Posted on February 9th, 2014 at 5:29 pm Reply | Quote
  • manoj Says:

    Hi Emil, it’s awesome stuff! Tried it in my C# Xamarin project and I’m glad i found this article!!!

    Posted on February 11th, 2014 at 1:52 pm Reply | Quote
  • Jordan Says:

    @Emil Adjiev Alright. I’ll check it.

    Posted on February 17th, 2014 at 4:09 pm Reply | Quote
  • Rhythm Says:

    Hi Emil, i am working on to search nearby places. Is it possible to use your code to get directions to searched places.
    Thanks

    Posted on March 5th, 2014 at 10:50 am Reply | Quote
  • Emil Adjiev Says:

    @Rhythm Hey, as long as you have the lat, long coordinates of both locations I don’t see why not : )

    Posted on March 5th, 2014 at 11:07 am Reply | Quote
  • Rhythm Says:

    @Emil Adjiev Thanks for the reply…

    Posted on March 12th, 2014 at 2:50 am Reply | Quote
  • Krishna Says:

    Hi Emil Adjiev,

    Thanks for the nice tutorial. I have one doubt i their any api available for voice over the navigation. If it is available please give some guidance in the same

    Posted on March 15th, 2014 at 9:44 pm Reply | Quote
  • sharsad Says:

    How can i fit the direction in screen.

    my direction always out side the screen.can i show both start and end marker to the screen

    thanks.

    Posted on March 20th, 2014 at 2:22 pm Reply | Quote
  • SHARATH Says:

    Thank you so much wonderful coding very helpful :)

    Posted on May 6th, 2014 at 4:23 pm Reply | Quote
  • crushman Says:

    Question. why use xml instead of json?

    Posted on May 11th, 2014 at 6:54 am Reply | Quote
  • Emil Adjiev Says:

    @crushman Hey, both are ways to transfer data over the internet so I don’t really see any difference in using JSON over XML or the other way around in this case.

    Posted on May 11th, 2014 at 8:30 pm Reply | Quote
  • Ciprian Says:

    Thanks man

    Posted on June 2nd, 2014 at 11:09 pm Reply | Quote
  • Ladi Says:

    You saved me a lot of work. Thank you!

    Posted on June 5th, 2014 at 2:37 pm Reply | Quote
  • kaleem Says:

    Hi Emil,
    Im trying to connect two cities belonging to two different nations,in some scenarios your code works perfectly,but for many other scenarios it just shows one of the location without any polyline drawn.

    Posted on August 7th, 2014 at 3:45 pm Reply | Quote
  • Emil Adjiev Says:

    @kaleem Hi, When the polyline is not getting drawn, it means that the response you are getting from Google Directions API basically returns you no path from one point to another. This might happen when there is no actual road connection the two location you are trying to show driving direction for.

    Posted on August 20th, 2014 at 6:27 pm Reply | Quote

Leave a comment