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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T03:06:00+00:00 2026-05-22T03:06:00+00:00

Using an ArrayList of GeoPoints, I’m looking to draw points on a map and

  • 0

Using an ArrayList of GeoPoints, I’m looking to draw points on a map and connect them with a line. I’ve got the “point” part working, but not the lines. My ItemizedOverlay class:

private class myItemizedOverlay extends ItemizedOverlay<OverlayItem>
{
    private ArrayList<OverlayItem> items = new ArrayList<OverlayItem>();
    private ArrayList<GeoPoint> geoPoints = new ArrayList<GeoPoint>();
    private int color;

    public myItemizedOverlay (Drawable marker, ArrayList<GeoPoint> gp, int c)
    {
        super(marker);
        geoPoints = gp;
        color = c;

        boundCenter(marker);

        for (int i = 0; i < geoPoints.size() - 1; i++)
        {
            items.add(new OverlayItem(geoPoints.get(i)));
        }

        populate();
    }

    @Override
    protected OverlayItem createItem(int i)
    {
        return items.get(i);
    }

    @Override
    public void draw(Canvas canvas, MapView mapView, boolean shadow)
    {
        super.draw(canvas, mapView, false);

        Paint paint = new Paint();
        paint.setColor(color);
        paint.setDither(true);
        paint.setAntiAlias(true);
        paint.setStyle(Paint.Style.FILL_AND_STROKE);
        paint.setStrokeJoin(Paint.Join.ROUND);
        paint.setStrokeCap(Paint.Cap.ROUND);
        paint.setStrokeWidth(2);

        Point p1 = new Point();
        Point p2 = new Point();

        for (int i = 1; i < geoPoints.size() - 1; i++)
        {
            mapView.getProjection().toPixels(geoPoints.get(i), p1);
            int x1 = p1.x;
            int y1 = p1.y;

            mapView.getProjection().toPixels(geoPoints.get(i - 1), p2);
            int x2 = p2.x;
            int y2 = p2.y;

            canvas.drawLine(x1, y1, x2, y2, paint);
        }
    }

    @Override
    public int size()
    {
        return items.size();
    }
}

called with:

myItemizedOverlay mo = new myItemizedOverlay(marker, geoPoints, color);
mapView.getOverlays().add(mo);

I’m finding that “geoPoints” is empty in the overridden “draw” method, and I can’t figure out why. Even more confusing is that “color” is /not/ empty, and both “color” and “geoPoints” are assigned the same way. Can anybody recommend a solution?

  • 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-22T03:06:00+00:00Added an answer on May 22, 2026 at 3:06 am

    You’re assigning gp to geoPoints. I expect somewhere else you are clearing gp. You should be doing a copy:

    geoPoints = new ArrayList<GeoPoint>(geoPoints.size());
    for (int i = 0; i < geoPoints.size() - 1; i++)
            {
                geoPoints.add(gp.get(i));
                items.add(new OverlayItem(geoPoints.get(i)));
            }
    

    Try that and let me know how that works.

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

Sidebar

Related Questions

I am looking to remove an element from an ArrayList using a query, E.g.
If I'm using an ArrayList in C#.NET, is the order guaranteed to stay the
How would I get the length of an ArrayList using a JSF EL expression?
Its known that Java ArrayList is implemented using arrays and initializes with capacity of
I'm building a thesaurus using a HashMap <String,ArrayList<String>> to hold words and their synonyms
i am able to get my bitmap set of points (as an array) using
I'm using arraylist in java and I need to add integers during 10 iterations
I'm doing a simple program using arraylist. But I've encountered an error. After deleting
I have a problem with ArrayList. I'm using ArrayList like this: private ArrayList<Playlist> mPlaylists;
I want to store few strings into an array using ArrayList. How can I

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.