简体   繁体   中英

How to draw dotted lines between geopoints on map in android?

I have refer the link here Drawing dotted (....)trail path instead of a line (________) , in that

Bitmap bmp = BitmapFactory.decodeResource(this.getResources(),R.drawable.greenflag);
Bitmap bmp = BitmapFactory.decodeResource(this.getResources(),R.drawable.redflag);

In drawble.greenflag, that is image file or xml file ?

use this to draw line between two geo points

class MyOverlay extends Overlay 
{
  public MyOverlay() {
  }
  public void draw(Canvas canvas, MapView mapv, boolean shadow) {
   super.draw(canvas, mapv, shadow);
   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(100);
   for (int i = 0; i < numPoints - 1; i++) {
    float latiA = (float) Double.parseDouble(latlong[i].getLat());
    float longiA = (float) Double.parseDouble(latlong[i].getLon());
    float latiB = (float) Double.parseDouble(latlong[i + 1].getLat());
    float longiB = (float) Double.parseDouble(latlong[i + 1].getLon());
    //distance = getDistance(latiA, longiA, latiB, longiB);
    int latA = (int) (1000000 * Double.parseDouble(latlong[i].getLat()));
    int longA = (int) (1000000 * Double.parseDouble(latlong[i].getLon()));
    int latB = (int) (1000000 * Double.parseDouble(latlong[i + 1].getLat()));
    int longB = (int) (1000000 * Double.parseDouble(latlong[i + 1].getLon()));
    GeoPoint gP1 = new GeoPoint(latA, longA);
    GeoPoint gP2 = new GeoPoint(latB, longB);
    Point p1 = new Point();
    Point p2 = new Point();
    Path path = new Path();
    projection.toPixels(gP1, p1);
    projection.toPixels(gP2, p2);
    path.moveTo(p2.x, p2.y);
    path.lineTo(p1.x, p1.y);
    canvas.drawPath(path, mPaint);
   }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM