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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:25:49+00:00 2026-05-31T02:25:49+00:00

I am trying to draw an overlay which will show a box and text

  • 0

I am trying to draw an overlay which will show a box and text within that box but it seems not to be display.

The overlay class is shown below

public class StatsOverlay extends Overlay 
{
Paint paint;
double altitude;
float speed;
float distance;
float maxSpeed;
long time;
double calories;
boolean showStats;

public StatsOverlay()
{

}

public void draw(Canvas canvas, MapView mapView, Paint paint, boolean shadow)
{
    super.draw(canvas, mapView, shadow);
    if(showStats == true)
    {
                    paint = new Paint();
        paint.setAntiAlias(true);
        paint.setARGB(80, 245, 245, 245);
        canvas.drawRect(0, 0, 350, 100, paint);
        paint.setTextSize(15);
        paint.setARGB(280, 0, 0, 0);

        canvas.drawText("Time: "+(time/60)+":"+(time%60)+"  Calories: "+calories+"  Distance: "+distance+"KM\n"+"Speed: "+speed+"KM/H   Max Speed: "+maxSpeed+"KM/H", 8, 14, paint);
    }
}

public void setStats(long time, float distance, float speed, float maxSpeed, double calories)
{
    this.time = time/1000;
    this.distance = distance;
    this.speed = speed;
    this.maxSpeed = maxSpeed;
    this.calories = calories;

}
  }

It never gets into the draw method at all.

This is snippet from code that calls the overlay.

public class Begin_Run_Map extends MapActivity implements LocationListener 
{

   //Other variables declared here for calculations

   //Overlay variables
   MyLocationOverlay myLocOver;
StatsOverlay statsOverlay;

public void onCreate(Bundle savedStateInstance)
{
    super.onCreate(savedStateInstance);
    setContentView(R.layout.race_run);

            //Setting up of the mapview, initalising variables and setting up of location manager etc done here

            mapView = (MapView) findViewById(R.id.race);
    mapView.setSatellite(false);
    mapView.setBuiltInZoomControls(true);
    mapView.displayZoomControls(true);

    mapCon = mapView.getController();



     screenOverlays = mapView.getOverlays();

    myLocOver = new MyLocationOverlay(this,mapView);
    statsOverlay = new StatsOverlay();
    screenOverlays.add(statsOverlay);
    screenOverlays.add(myLocOver);
      }

In the onLocationChange(Location loc) method is call a method centerOnLocation(Location loc) which passes the values to the display overlay class

  private void centerOnLocation(Location loc) 
{
    // TODO Auto-generated method stub
    double lat = loc.getLatitude();
    double lng = loc.getLongitude();

    GeoPoint me = new GeoPoint((int) (lat * 1E6),(int) (lng * 1E6));
    mapCon.animateTo(me);
    if(statsOverlay != null)
    {

        statsOverlay.setStats(times.get(times.size()-1), distance, avg_Speed, maxSpeed, caloriesBurned);
    }
}

The other overlay of MyLocationOverlay works fine as well as another overlay that shows the users previous points.

Thanks for the help

  • 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-31T02:25:50+00:00Added an answer on May 31, 2026 at 2:25 am

    Declare the draw function like this:

    @Override
    public boolean draw(Canvas canvas, MapView mv, boolean shadow, long when){
            super.draw(canvas, mv, shadow);
            //declare the paint object here
            Paint paint = new Paint();
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to draw some text in the corner of a rectangle but I
I'm currently trying to draw shapes with 2D Arrays. In my class there is
I am trying to draw a series of rectangles using OpenGL but some of
I'm trying to draw a vertical scrollbar for my G15 applet, but am having
I'm trying to draw vertical text in win32 GDI api. I call CreateFont() with
I'm trying to draw a hexagonal lattice in Qt, in which each hexagon needs
I'm trying to draw a route onto my MapView. I've extended Overlay and implemented
basically i am trying to draw the path i.e road path. for that i
Using GTK, I'm trying to overlay a More prompt (but it could just as
I'm trying to overlay glyphs from different fonts, but it's hard to get them

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.