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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:41:47+00:00 2026-06-01T12:41:47+00:00

I have a program where I want to draw a line between two points.

  • 0

I have a program where I want to draw a line between two points. I then want another line to draw between another two points. When I draw one line it removes the previous line. I have tried making both lines different Overlays but it still removes the old line and puts in the new line. Do I prevent this from happing and how do I make all the Overlays stay? Any help would be greatly appreciated.

The Overlay class in inside the Activity class.

This is in onKeyDown()

case KeyEvent.KEYCODE_8:
            twoPoints.add(a);
            twoPoints.add(b);

            MapOverlay newOverlay = new MapOverlay();
            listOfOverlays = mapView.getOverlays();
            listOfOverlays.add(newOverlay);

            mapView.postInvalidate();
            System.out.println("Test overlays 1 Point");

            break;

        case KeyEvent.KEYCODE_9:
            twoPoints.remove(1);
            twoPoints.add(c);

            MapOverlay newOverlay1 = new MapOverlay();
            listOfOverlays.add(newOverlay1);
            mapView.postInvalidate();

            System.out.println("Test Overlays 2 Point");
            break;

And this is the Overlay class:

   public class MapOverlay extends com.google.android.maps.Overlay
   {        
    @Override
    public void draw(Canvas canvas, MapView mapView, boolean shadow)
    {       
        super.draw(canvas,mapView,shadow);

        //-- Create new paint object --
        Paint mPaint = new Paint();
        mPaint.setDither(true);
        mPaint.setColor(Color.RED);
        mPaint.setStyle(Paint.Style.STROKE);
        mPaint.setStrokeJoin(Paint.Join.ROUND);
        mPaint.setStrokeCap(Paint.Cap.ROUND);
        mPaint.setStrokeWidth(2);

        //System.out.println("Point 1");


            //System.out.println("Point 2");

            for(int i =0; i < twoPoints.size()-1;i++)
            {
                Point screenPt1 = new Point();
                mapView.getProjection().toPixels(twoPoints.get(i), screenPt1);

                Point screenPt2 = new Point();
                mapView.getProjection().toPixels(twoPoints.get(i+1), screenPt2);

                canvas.drawLine(screenPt1.x, screenPt1.y, screenPt2.x, screenPt2.y, mPaint);

                System.out.println("Point 3");
            }   

        //mapView.invalidate();
    }
}

It has been really confusing me for a while now.

  • 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-01T12:41:48+00:00Added an answer on June 1, 2026 at 12:41 pm

    Eyespyus was on the right track the problem was that I had the Overlay class in the activity and was changing the array that both used. Moving the class outside the activity fixed the problem.

    This was a really silly mistake and I thank everyone for taking the time to look at this, I am very new to Android.

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

Sidebar

Related Questions

In my program I want to draw a simple score line graph. I have
I'm coding a program where I want to draw a card, and then delete
I have a program and want to debug it in gdb. Will I see
I have a program where I want to scrap some useful study material for
I have a program that I want to either hide or show certain UIbuttons
I have a small program I want to execute to test something #include <map>
I have program that runs fast enough. I want to see the number of
I want to have a program that reads metadata from an MP3 file. My
I have a console program and I want if the user press ctrl-z the
I have a program that is been implemented in C++ which I now want

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.