Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid custom Overlay not drawing
    text
    copied!<p>I am trying to draw an overlay which will show a box and text within that box but it seems not to be display. </p> <p>The overlay class is shown below</p> <pre><code>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; } } </code></pre> <p>It never gets into the draw method at all.</p> <p>This is snippet from code that calls the overlay.</p> <pre><code>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); } </code></pre> <p>In the <code>onLocationChange(Location loc)</code> method is call a method <code>centerOnLocation(Location loc)</code> which passes the values to the display overlay class</p> <pre><code> 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); } } </code></pre> <p>The other overlay of MyLocationOverlay works fine as well as another overlay that shows the users previous points.</p> <p>Thanks for the help</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload