Android MyOverlay extends Overlay


/ Published in: Java
Save to your folder(s)



Copy this code and paste it in your HTML
  1. private class MyOverlay extends Overlay {
  2. private GeoPoint center;
  3. private float radius;
  4. private Paint cPaint;
  5.  
  6. public MyOverlay(GeoPoint c) {
  7. center = c;
  8. radius = 20;
  9. cPaint = new Paint();
  10. }
  11.  
  12. @Override
  13. public void draw(Canvas canvas, MapView mapView, boolean shadow) {
  14. super.draw(canvas, mapView, shadow);
  15. if (shadow == false) {
  16. // class exercise
  17. // Step 1: get pixel coordinate of center (in GeoPoint)
  18. Point screenPt = new Point();
  19. mapView.getProjection().toPixels(center, screenPt);
  20.  
  21. // Step 2: draw a circle at the converted pixel coordinate
  22. cPaint.setColor(Color.RED);
  23. cPaint.setAlpha(100);
  24. canvas.drawCircle(screenPt.x, screenPt.y, radius, cPaint);
  25. }
  26.  
  27. }
  28. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.