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

  • SEARCH
  • Home
  • 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 7863765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:35:11+00:00 2026-06-02T23:35:11+00:00

I am trying to build a GPS app which can show directions between 2

  • 0

I am trying to build a GPS app which can show directions between 2 places. For decoding the polylines I am using code from here: Decoding Polylines from Google Maps Direction API with Java. I want to show my route more accurately than this, I am able to do that through kml but it works for very small distances only after which file size reaches limit. Here is screenshot for Boston-Seattle where lines on the map do not follow road but intersect roads
enter image description here

Here is how I am using directions API

public void drawRoute(String source, String destination)
{
    String strURL = "http://maps.google.com/maps/api/directions/xml?origin=" + source + 
            "&destination=" + destination + "&sensor=false&mode=driving";

    String url = strURL.replace(" ", "%20");
    HttpGet get = new HttpGet(url);
    String strResult = "";
    try {
        HttpParams httpParameters = new BasicHttpParams();
        HttpConnectionParams.setConnectionTimeout(httpParameters, 3000);
        HttpClient httpClient = new DefaultHttpClient(httpParameters); 
        HttpResponse httpResponse = null;
        httpResponse = httpClient.execute(get);
        if (httpResponse.getStatusLine().getStatusCode() == 200){
            strResult = EntityUtils.toString(httpResponse.getEntity());
        }
    }
    catch (Exception e){ }

    if (-1 == strResult.indexOf("<status>OK</status>")){
        this.finish();
        return;
    }

    int pos = strResult.indexOf("<overview_polyline>");
    pos = strResult.indexOf("<points>", pos + 1);
    int pos2 = strResult.indexOf("</points>", pos);
    strResult = strResult.substring(pos + 8, pos2);

    List<GeoPoint> points = decodePoly(strResult);

    RouteOverlay mOverlay = new RouteOverlay(points);
    overlayList.add(mOverlay);

    if (points.size() >= 2){
        controller.animateTo(points.get(0));
    }
    map.invalidate();
}   

Here is my RouteOverlay class:

public class RouteOverlay extends Overlay{
private List<GeoPoint> points;
private Paint paint;

public RouteOverlay(List<GeoPoint> points) {
    this.points = points;
    paint = new Paint();
    paint.setColor(Color.BLUE);
    paint.setAlpha(150);
    paint.setAntiAlias(true);
    paint.setStyle(Paint.Style.FILL_AND_STROKE);
    paint.setStrokeWidth(4);
}

@Override
public void draw(Canvas canvas, MapView mapView, boolean shadow) 
{
    if (!shadow) 
    {
        Projection projection = mapView.getProjection();
        if (points != null && points.size() >= 2) 
        {
            Point start = new Point();
            projection.toPixels(points.get(0), start);
            for (int i = 1; i < points.size(); i++) 
            {
                Point end = new Point();
                projection.toPixels(points.get(i), end);
                canvas.drawLine(start.x, start.y, end.x, end.y, paint);
                start = end;
            }
        }
    }
}
}
  • 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-06-02T23:35:12+00:00Added an answer on June 2, 2026 at 11:35 pm

    Refer this link to draw driving path in your application. You just need to add the four classes present in the link in your project and call the below lines when you need to display the route.

    SharedData data = SharedData.getInstance();
    data.setAPIKEY("0RUTLH7cqd6yrZ0FdS0NfQMO3lioiCbnH-BpNQQ");//set your map key here
    data.setSrc_lat(17);//set your src lat
    data.setSrc_lng(78);//set your src lng
    data.setDest_lat(18);//set your dest lat
    data.setDest_lng(77);//set your dest lng
    startActivity(new Intent(YourActivity.this,RoutePath.class));//add RoutePath in your manifeast file
    

    //Also add the permission to your manifeast file

    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
    
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    
    <uses-permission android:name="android.permission.INTERNET"></uses-permission>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying build a method which returns the shortest path from one node to
Trying to build dynamic output from json and using jq/template tmpl display rows/columns. Somehow
I`m trying to build a application using the Fragment/Tabs and Pager from the android
Im trying to build a feeds application in php in which im using a
Trying to build a Metro app using Javascript and having issues with IndexedDb. I
I'm trying build an App Engine connected Android application and am having some problems
Trying to build Xuggler under Windows. Xuggler is core native code functions wrapped into
Trying to build a legacy code in VS2005 and get errors in VC header
Im trying to build call to action button on my site using jQuery. I
I am trying build a DataTable one row at a time using the following

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.