我在Android中使用itemizedoverlay遇到异常错误.
我正在创建一个GPS跟踪设备,该设备可以绘制数据库中存储的航点之间的路线.
当我通过Eclipse中的仿真器提供前两组经度和纬度点时,它会按照我的意愿绘制一条红线,但是如果我发送另一个GPS点,它将设置为动画点,但不会从该点绘制一条线最后一点.
public class MyOverlay extends itemizedoverlay<OverlayItem> { // private Projection projection;private Paint linePaint;private Vector<GeoPoint> points;public MyOverlay(Drawable defaultMarker) { super(defaultMarker); points = new Vector<GeoPoint>(); //set colour,stroke wIDth etc. linePaint = new Paint(); linePaint.setARGB(255,255,0); linePaint.setstrokeWIDth(3); linePaint.setDither(true); linePaint.setStyle(Style.FILL); linePaint.setAntiAlias(true); linePaint.setstrokeJoin(Paint.Join.ROUND); linePaint.setstrokeCap(Paint.Cap.ROUND);}public voID addPoint(GeoPoint point) { points.addElement(point);}public voID draw(Canvas canvas,MapVIEw vIEw,boolean shadow) { int size = points.size(); Point lastPoint = new Point(); if(size == 0) return; vIEw.getProjection().topixels(points.get(0),lastPoint); Point point = new Point(); for(int i = 1; i<size; i++){ vIEw.getProjection().topixels(points.get(i),point); canvas.drawline(lastPoint.x,lastPoint.y,point.x,point.y,linePaint); lastPoint = point; }}@OverrIDeprotected OverlayItem createItem(int arg0) { // Todo auto-generated method stub return null;}@OverrIDepublic int size() { // Todo auto-generated method stub return 0;}}
最佳答案在您的代码中,draw()方法仅被调用一次,因此永远不会被调用.填充方法将重新填充列表中每次出现的所有叠加点.因此,它将再次调用draw方法,它将为您绘制一条线.package com.example.mymap;import java.util.ArrayList;import androID.graphics.Canvas;import androID.graphics.Paint;import androID.graphics.Point;import androID.graphics.drawable.Drawable;import com.Google.androID.maps.GeoPoint;import com.Google.androID.maps.itemizedoverlay;import com.Google.androID.maps.MapVIEw;import com.Google.androID.maps.OverlayItem;public class ItemOverLay extends itemizedoverlay<OverlayItem> {private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();GeoPoint prePoint=null,currentPoint=null;MapVIEw mapVIEw=null;Paint paint=new Paint();public ItemOverLay(GeoPoint prePoint,GeoPoint currentPoint,Drawable defaultMarker,MapVIEw mapvIEw) { super(boundCenterBottom(defaultMarker)); this.currentPoint=currentPoint; this.prePoint = prePoint; mapVIEw=mapvIEw; // Todo auto-generated constructor stub}public ItemOverLay(Drawable defaultMarker) { super(defaultMarker); // Todo auto-generated constructor stub}public voID addOverlay(OverlayItem item){ mOverlays.add(item); populate();}@OverrIDeprotected OverlayItem createItem(int i) { // Todo auto-generated method stub return mOverlays.get(i);} @OverrIDe public voID draw(Canvas canvas,MapVIEw mapVIEw,boolean shadow) { super.draw(canvas,mapVIEw,shadow); Paint paint=new Paint(); Point screenCoords=new Point(); Point screenCoords1=new Point(); mapVIEw.getProjection().topixels(prePoint,screenCoords); int x1=screenCoords.x; int y1=screenCoords.y; mapVIEw.getProjection().topixels(currentPoint,screenCoords1); int x2=screenCoords1.x; int y2=screenCoords1.y; paint.setstrokeWIDth(1); canvas.drawline(x1,y1,x2,y2,paint); } @OverrIDe public int size() { // Todo auto-generated method stub return mOverlays.size(); }
} 总结
以上是内存溢出为你收集整理的Java-叠加层仅在Android中的前2个GPS点之间绘制线条 全部内容,希望文章能够帮你解决Java-叠加层仅在Android中的前2个GPS点之间绘制线条 所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)