Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6140063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:04:11+00:00 2026-05-23T18:04:11+00:00

I’m trying to use the Google directions API to show directions on my mapview

  • 0

I’m trying to use the Google directions API to show directions on my mapview but I am having difficulties getting the data from the JSON response. I can get the “levels” and “points” strings but can’t work out how to decode them to points on the map.

Any help would be much appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T18:04:12+00:00Added an answer on May 23, 2026 at 6:04 pm

    I have a class which can decode them for you, add the class below then call in your code like this:

    int[] decodedZoomLevels = PolylineDecoder.decodeZoomLevels(levels);
    GeoPoint[] gPts = PolylineDecoder.decodePoints(points, decodedZoomLevels.length);
    

    where points and levels are the data you’ve extracted from the JSON response. You can then go through the array of geopoints drawing a line between them to display your directions.

    Hope this helps! Kenny


    EDIT: It would seem that the google directions API no longer returns the zoom levels string as part of the JSON response, not to worry though, all we were using this for was to check the number of points, so we can simply put these into a list like:

    public static List <GeoPoint> decodePoints(String encoded_points){
    int index = 0;
    int lat = 0;
    int lng = 0;
    List <GeoPoint> out = new ArrayList<GeoPoint>();
    
    try {
        int shift;
        int result;
        while (index < encoded_points.length()) {
            shift = 0;
            result = 0;
            while (true) {
                int b = encoded_points.charAt(index++) - '?';
                result |= ((b & 31) << shift);
                shift += 5;
                if (b < 32)
                    break;
            }
            lat += ((result & 1) != 0 ? ~(result >> 1) : result >> 1);
    
            shift = 0;
            result = 0;
            while (true) {
                int b = encoded_points.charAt(index++) - '?';
                result |= ((b & 31) << shift);
                shift += 5;
                if (b < 32)
                    break;
            }
            lng += ((result & 1) != 0 ? ~(result >> 1) : result >> 1);
            /* Add the new Lat/Lng to the Array. */
            out.add(new GeoPoint((lat*10),(lng*10)));
        }
        return out;
    }catch(Exception e) {
        e.printStackTrace();
    }
    return out;
    }
    

    EDIT: OLD CODE

    public class PolylineDecoder {
    /**
     * Transform a encoded PolyLine to a Array of GeoPoints.
     * Java implementation of the original Google JS code.
     * @see Original encoding part: <a href="http://code.google.com/apis/maps/documentation/polylinealgorithm.html">http://code.google.com/apis/maps/documentation/polylinealgorithm.html</a>
     * @return Array of all GeoPoints decoded from the PolyLine-String.
     * @param encoded_points String containing the encoded PolyLine. 
     * @param countExpected Number of points that are encoded in the PolyLine. Easiest way is to use the length of the ZoomLevels-String. 
     * @throws DecodingException 
     */
    public static GeoPoint[] decodePoints(String encoded_points, int countExpected){
        int index = 0;
        int lat = 0;
        int lng = 0;
        int cnt = 0;
        GeoPoint[] out = new GeoPoint[countExpected];
    
        try {
            int shift;
            int result;
            while (index < encoded_points.length()) {
                shift = 0;
                result = 0;
                while (true) {
                    int b = encoded_points.charAt(index++) - '?';
                    result |= ((b & 31) << shift);
                    shift += 5;
                    if (b < 32)
                        break;
                }
                lat += ((result & 1) != 0 ? ~(result >> 1) : result >> 1);
    
                shift = 0;
                result = 0;
                while (true) {
                    int b = encoded_points.charAt(index++) - '?';
                    result |= ((b & 31) << shift);
                    shift += 5;
                    if (b < 32)
                        break;
                }
                lng += ((result & 1) != 0 ? ~(result >> 1) : result >> 1);
                /* Add the new Lat/Lng to the Array. */
                out[cnt++] = new GeoPoint((lat*10),(lng*10));
            }
            return out;
        }catch(Exception e) {
            e.printStackTrace();
        }
        return out;
    }
    
    public static int[] decodeZoomLevels(String encodedZoomLevels){
        int[] out = new int[encodedZoomLevels.length()];
        int index = 0;
    
        for(char c : encodedZoomLevels.toCharArray())
            out[index++] = c - '?';
        return out;
    
    }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I want to construct a data frame in an Rcpp function, but when I
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm making a simple page using Google Maps API 3. My first. One marker
Basically, what I'm trying to create is a page of div tags, each has
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
Seemingly simple, but I cannot find anything relevant on the web. What is the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.