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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:04:04+00:00 2026-05-26T16:04:04+00:00

I need to draw a Polygon from several points (I have their latitude, longitude).

  • 0

I need to draw a Polygon from several points (I have their latitude, longitude).
I am basing my implementation from these two answers:
Drawing an empty polygon given a set of points on a Map Overylay (Android 2.1)
Drawing a line/path on Google Maps

In my MapOverlayAction.java I set the overlay for some pins like this:

mapOverlays.add(itemizedoverlay);
setLocationOverlay(mapView, mapController);

where itemizedoverlay is an array of OverlayItems

This works fine. But I also need to draw a polygon for these points (where each point is a vertex). So what I do is:

Path path = new Path();

 for (int j = 0; j < itemizedoverlay.size(); j++) {

   GeoPoint gP1 = itemizedoverlay.getItem(j).getPoint();
   Point currentScreenPoint = new Point();

    Projection projection = mapView.getProjection();
    projection.toPixels(gP1, currentScreenPoint);

    if (j == 0)
      path.moveTo(currentScreenPoint.x, currentScreenPoint.y); 
    else
      path.lineTo(currentScreenPoint.x, currentScreenPoint.y);
}

In both of the answersI am basing my solution, the following method is being called:

    Paint   mPaint = new Paint();
    mPaint.setDither(true);
    mPaint.setColor(Color.RED);
    mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
    mPaint.setStrokeJoin(Paint.Join.ROUND);
    mPaint.setStrokeCap(Paint.Cap.ROUND);
    mPaint.setStrokeWidth(2);    

    canvas.drawPath(path, mPaint);

My question is, where do I get that canvas from?
I have all this code in my activity class.

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-26T16:04:05+00:00Added an answer on May 26, 2026 at 4:04 pm

    You will need to subclass the Overlay class and override the Draw method to get your canvas.

    then instantiate your new class and add it to the list of Overlays to have it appear on the map. This question should help.

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

Sidebar

Related Questions

i need to draw a polygon of n sides given 2 points (the center
I have a concave polygon I need to draw in OpenGL. The polygon is
I need to draw on a TPanel, ideally directly so I don't have another
I need to draw a .png image on an UIView. I have no clue
I need to draw several simple objects (polygons composed by lines and arcs, eventually
Right now I am trying to draw a polygon in Cocos2d, but I need
I need to draw polygon using mouse and mark a particular area on Google
I need draw rectangle with two circle holes inside. The problem is in circles
I need to draw a texture on a square polygon, not a cube, i
I need to draw a polygon in Pascal(dev-pascal) which has semicircles at its sides.

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.