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 7661409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:35:41+00:00 2026-05-31T13:35:41+00:00

i want the source code for path tracking program in android. i see the

  • 0

i want the source code for path tracking program in android.
i see the code in
How to draw a path on a map using kml file?
public void drawPath(NavigationDataSet navSet, int color, MapView mMapView01) {

Log.d(myapp.APP, "map color before: " + color);        

// color correction for dining, make it darker
if (color == Color.parseColor("#add331")) color = Color.parseColor("#6C8715");
Log.d(myapp.APP, "map color after: " + color);

Collection overlaysToAddAgain = new ArrayList();
for (Iterator iter = mMapView01.getOverlays().iterator(); iter.hasNext();) {
    Object o = iter.next();
    Log.d(myapp.APP, "overlay type: " + o.getClass().getName());
    if (!RouteOverlay.class.getName().equals(o.getClass().getName())) {
        // mMapView01.getOverlays().remove(o);
        overlaysToAddAgain.add(o);
    }
}
mMapView01.getOverlays().clear();
mMapView01.getOverlays().addAll(overlaysToAddAgain);

String path = navSet.getRoutePlacemark().getCoordinates();
Log.d(myapp.APP, "path=" + path);
if (path != null && path.trim().length() > 0) {
    String[] pairs = path.trim().split(" ");

    Log.d(myapp.APP, "pairs.length=" + pairs.length);

    String[] lngLat = pairs[0].split(","); // lngLat[0]=longitude lngLat[1]=latitude lngLat[2]=height

    Log.d(myapp.APP, "lnglat =" + lngLat + ", length: " + lngLat.length);

    if (lngLat.length<3) lngLat = pairs[1].split(","); // if first pair is not transferred completely, take seconds pair //TODO 

    try {
        GeoPoint startGP = new GeoPoint((int) (Double.parseDouble(lngLat[1]) * 1E6), (int) (Double.parseDouble(lngLat[0]) * 1E6));
        mMapView01.getOverlays().add(new RouteOverlay(startGP, startGP, 1));
        GeoPoint gp1;
        GeoPoint gp2 = startGP;

        for (int i = 1; i < pairs.length; i++) // the last one would be crash
        {
            lngLat = pairs[i].split(",");

            gp1 = gp2;

            if (lngLat.length >= 2 && gp1.getLatitudeE6() > 0 && gp1.getLongitudeE6() > 0
                    && gp2.getLatitudeE6() > 0 && gp2.getLongitudeE6() > 0) {

                // for GeoPoint, first:latitude, second:longitude
                gp2 = new GeoPoint((int) (Double.parseDouble(lngLat[1]) * 1E6), (int) (Double.parseDouble(lngLat[0]) * 1E6));

                if (gp2.getLatitudeE6() != 22200000) { 
                    mMapView01.getOverlays().add(new RouteOverlay(gp1, gp2, 2, color));
                    Log.d(myapp.APP, "draw:" + gp1.getLatitudeE6() + "/" + gp1.getLongitudeE6() + " TO " + gp2.getLatitudeE6() + "/" + gp2.getLongitudeE6());
                }
            }
            // Log.d(myapp.APP,"pair:" + pairs[i]);
        }
        //routeOverlays.add(new RouteOverlay(gp2,gp2, 3));
        mMapView01.getOverlays().add(new RouteOverlay(gp2, gp2, 3));
    } catch (NumberFormatException e) {
        Log.e(myapp.APP, "Cannot draw route.", e);
    }
}
// mMapView01.getOverlays().addAll(routeOverlays); // use the default color
mMapView01.setEnabled(true);

}
but i am unable to execute the code.
if you donot mind can any once give the entire source code .

thanks.

  • 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-31T13:35:42+00:00Added an answer on May 31, 2026 at 1:35 pm

    I have two classes HomeActivity and MyOverlay to draw path in google map
    here is HomeActivity :

    MapView mapView;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Log.e("Home", " activity created");
        mapView = (MapView) findViewById(R.id.mapview);
        double src_lat = 28.011022; // the testing source  28.011022,73.323802
        double src_long = 73.323802;
        double dest_lat = 28.008389; // the testing destination   28.008389,73.33599
        double dest_long = 73.33599;
    
        Log.e("Home ", " Strting drawing path");
        GeoPoint srcGeoPoint = new GeoPoint((int) (src_lat * 1E6),
                (int) (src_long * 1E6));
        GeoPoint destGeoPoint = new GeoPoint((int) (dest_lat * 1E6),
                (int) (dest_long * 1E6));
        Log.e("Home ", " Strting drawing path");
    
        List<Overlay> mapOverlays = mapView.getOverlays();
        Drawable drawable = this.getResources().getDrawable(R.drawable.darkgreen_marker);
        mapView.getOverlays();
        OverlayItem overlayitem = new OverlayItem(srcGeoPoint, "Hello!", "This is your position");
        overLay marker_overlay=new overLay(drawable);
        marker_overlay.addOverlay(overlayitem);
        mapOverlays.add(marker_overlay);
        overlayitem = new OverlayItem(destGeoPoint, "Theater Big ", "Go to this ");
        marker_overlay.addOverlay(overlayitem);
        mapOverlays.add(marker_overlay);
        //mapView.getOverlays().add(new overLay(null, destGeoPoint));
    
        DrawPath(srcGeoPoint, destGeoPoint, Color.GREEN, mapView);      
        mapView.getController().animateTo(srcGeoPoint);
        mapView.getController().setZoom(15);
        mapView.setBuiltInZoomControls(true);
    }
    
    @Override
    protected boolean isRouteDisplayed() {
    
        return false;
    }
    
    private void DrawPath(GeoPoint src,GeoPoint dest, int color, MapView mMapView01)
    {
        // connect to map web service
        StringBuilder urlString = new StringBuilder();
        urlString.append("http://maps.google.com/maps?f=d&hl=en");
        urlString.append("&saddr=");//from
        urlString.append( Double.toString((double)src.getLatitudeE6()/1.0E6 ));
        urlString.append(",");
        urlString.append( Double.toString((double)src.getLongitudeE6()/1.0E6 ));
        urlString.append("&daddr=");//to
        urlString.append( Double.toString((double)dest.getLatitudeE6()/1.0E6 ));
        urlString.append(",");
        urlString.append( Double.toString((double)dest.getLongitudeE6()/1.0E6 ));
        urlString.append("&ie=UTF8&0&om=0&output=kml");
        Log.e("Draw path  ","URL="+urlString.toString());
        // get the kml (XML) doc. And parse it to get the coordinates(direction route).
        Document doc = null;
    
        HttpURLConnection urlConnection= null;
        URL url = null;
        try
        {
            url = new URL(urlString.toString());
            urlConnection=(HttpURLConnection)url.openConnection();
            urlConnection.setRequestMethod("GET");
            urlConnection.setDoOutput(true);
            urlConnection.setDoInput(true);
            urlConnection.connect();
    
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            DocumentBuilder db = dbf.newDocumentBuilder();
            doc = db.parse(urlConnection.getInputStream());
            Log.e(" Home ", " response"+doc.toString());
            if(doc.getElementsByTagName("GeometryCollection").getLength()>0)
            {
                //String path = doc.getElementsByTagName("GeometryCollection").item(0).getFirstChild().getFirstChild().getNodeName();
                String path = doc.getElementsByTagName("GeometryCollection").item(0).getFirstChild().getFirstChild().getFirstChild().getNodeValue() ;
                Log.d("draw path ","path="+ path);
                String [] pairs = path.split(" ");
                String[] lngLat = pairs[0].split(","); // lngLat[0]=longitude lngLat[1]=latitude lngLat[2]=height
                // src
                GeoPoint startGP = new GeoPoint((int)(Double.parseDouble(lngLat[1])*1E6),(int)(Double.parseDouble(lngLat[0])*1E6));
                mMapView01.getOverlays().add(new MyOverLay(startGP,startGP,1));
                GeoPoint gp1;
                GeoPoint gp2 = startGP;
                for(int i=1;i<pairs.length;i++) // the last one would be crash
                {
                    lngLat = pairs[i].split(",");
                    gp1 = gp2;
                    // watch out! For GeoPoint, first:latitude, second:longitude
                    gp2 = new GeoPoint((int)(Double.parseDouble(lngLat[1])*1E6),(int)(Double.parseDouble(lngLat[0])*1E6));
                    mMapView01.getOverlays().add(new MyOverLay(gp1,gp2,2,color));
                    Log.d("Draw path","pair:" + pairs[i]);
                }
                mMapView01.getOverlays().add(new MyOverLay(dest,dest, 3)); // use the default color
            }
        }catch (MalformedURLException e){
            e.printStackTrace();
        }
        catch (IOException e){
            e.printStackTrace();
        }
        catch (ParserConfigurationException e){
            e.printStackTrace();
        }
        catch (SAXException e){
            e.printStackTrace();
        }
    }
    
    public class overLay extends ItemizedOverlay<OverlayItem>{
        private List<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
        GeoPoint gp1;
        Drawable marker;
    
        public overLay(Drawable marker) {
            super(marker);
            this.marker=marker;
        }
    
        public void addOverlay(OverlayItem overlay){
            mOverlays.add(overlay);
            Log.e(" Map Overlay __", " adding new item "+overlay);
            populate();
        }
    
        @Override
        public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when){
            Projection projection = mapView.getProjection();
            Point point = new Point();
            for(int i=0;i<mOverlays.size();i++){
                OverlayItem g = getItem(i);
                gp1=g.getPoint();
                projection.toPixels(gp1, point);
                  Bitmap bmp = BitmapFactory.decodeResource(
                            getResources(), R.drawable.marker_red);            
                        canvas.drawBitmap(bmp, point.x-10, point.y-35, null);
            }
            return super.draw(canvas, mapView, shadow, when);
        }
    
        @Override
        public boolean onTap(int index){
            /* GeoPonit p MapView mapView*/
            OverlayItem item = getItem(index);
            GeoPoint gp=item.getPoint();
            String msg=item.getSnippet();
    
            mapView.getController().animateTo(gp);
            Log.e("-- map view --", " marker clicked "+gp);
    
            LayoutInflater infalter=getLayoutInflater();
            final LinearLayout table = (LinearLayout)infalter.inflate(R.layout.popup_baloon_layout, null);  
            table.setWillNotDraw(false);
            final MapView.LayoutParams lp2 = new MapView.LayoutParams(
                    150,100,gp,-15,-10,MapView.LayoutParams.BOTTOM_CENTER);  
            TextView addrs=(TextView)table.findViewById(R.id.address);
            addrs.setText(msg);
            ImageView call_img=(ImageView)table.findViewById(R.id.imageView1);
            call_img.setOnClickListener(new OnClickListener() {
                @Override 
                public void onClick(View v) {
                    Log.e("__ Home __", " making call to 12345");
                    Bundle bundle=new Bundle();
                    mapView.removeView(table);
                    Intent intent = new Intent(Intent.ACTION_CALL);
                    intent.setData(Uri.parse("tel:" + bundle.getString("12345")));
                    HomeActivity.this.startActivity(intent);
    
                }
            });
    
            table.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    mapView.removeView(table);
                    //table=null;
                }
            });
    
            mapView.addView(table,lp2);
            return true;
        }
    
        @Override
        protected OverlayItem createItem(int i) {
            Log.e("Map Overlay __", " creating overlay item "+i);
            return mOverlays.get(i);
        }
    
        @Override
        public int size() {
            Log.e("Map Overlay __", " getting overlay size ");
            return mOverlays.size();
        }
    
    }
    

    and MyOverLay class :

    public class MyOverLay extends Overlay{
    private GeoPoint gp1;
    private GeoPoint gp2;
    //private int mRadius=6;
    private int mode=0;
    private int defaultColor;
    //private String text="";
    //private Bitmap img = null;
    private Context context;
    
    public MyOverLay(GeoPoint gp1,GeoPoint gp2,int mode,Context context){// GeoPoint is a int. (6E)
        this.gp1 = gp1;
        this.gp2 = gp2;
        this.mode = mode;
        defaultColor = 999; // no defaultColor
        this.context=context;
    }
    
    public MyOverLay(GeoPoint gp1,GeoPoint gp2,int mode, int defaultColor,Context context){
        this.gp1 = gp1;
        this.gp2 = gp2;
        this.mode = mode;
        this.defaultColor = defaultColor;
        this.context=context;
    }
    
    /*public void setText(String t){
        this.text = t;
    }
    
    public void setBitmap(Bitmap bitmap){
        this.img = bitmap;
    }*/
    
    public int getMode(){
        return mode;
    }
    
    @Override
    public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when){
        Projection projection = mapView.getProjection();
        if (shadow == false){
            Paint paint = new Paint();
            paint.setAntiAlias(true);
            Point point = new Point();
            projection.toPixels(gp1, point);
            // mode=1&#65306;start
            if(mode==1){
                if(defaultColor==999)
                paint.setColor(Color.BLUE);
                else
                paint.setColor(defaultColor);
                Bitmap bmp = BitmapFactory.decodeResource(
                        context.getResources(), R.drawable.marker_red);            
                    canvas.drawBitmap(bmp, point.x-10, point.y-35, null);
    
                /*RectF oval=new RectF(point.x - mRadius, point.y - mRadius,
                point.x + mRadius, point.y + mRadius);*/
                // start point
                //canvas.drawOval(oval, paint);
            }
            // mode=2&#65306;path
            else if(mode==2){
                if(defaultColor==999)
                paint.setColor(Color.RED);
                else
                paint.setColor(defaultColor);
                Point point2 = new Point();
                projection.toPixels(gp2, point2);
                paint.setStrokeWidth(5);
                paint.setAlpha(120);
                canvas.drawLine(point.x, point.y, point2.x,point2.y, paint);
            }
            /* mode=3&#65306;end */
            else if(mode==3){
            /* the last path */
    
                if(defaultColor==999)
                paint.setColor(Color.GREEN);
                else
                paint.setColor(defaultColor);
                Point point2 = new Point();
                projection.toPixels(gp2, point2);
                paint.setStrokeWidth(5);
                paint.setAlpha(120);
                canvas.drawLine(point.x, point.y, point2.x,point2.y, paint);
                Bitmap bmp = BitmapFactory.decodeResource(
                        context.getResources(), R.drawable.marker_red);            
                    canvas.drawBitmap(bmp, point.x-16, point.y-38, null);
                /*RectF oval=new RectF(point2.x - mRadius,point2.y - mRadius,
                point2.x + mRadius,point2.y + mRadius);
                paint.setAlpha(255);
                canvas.drawOval(oval, paint);*/
            }
        }
        return super.draw(canvas, mapView, shadow, when);
    }
    
    @Override
    public boolean onTap(GeoPoint p, MapView mapView){
    
        return false;
    }
    

    }

    These classes use kml to draw path between two locations.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When reading source code, I always want to know the full path of the
I wrote an android app for someone, but they want the source code because
I want see the source code of System.Web.Routing.RouteValueDictionary class. But Reflector can't disassemble it
I want to process each source code file after it has been preprocessed: myprocess
I want to integrate the zxing source code to my Android application. I have
Using Eclipse I want to view the source code for a core Java class
I want to generate the javadocs for an open-source code-base I'm using. But I'm
I want to get the path and source code of the __builtin__ module, where
I am working on the android gingerbread source code. I want to know where
How can I get source code from WebBrowser component? I want to get source

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.