线不是根据geopoint来的

时间:2011-12-05 01:41:32

标签: android

通过我的主要java文件,我调用覆盖,而不是我传递了geopoint,并且线条变得如此奇怪,甚至没有关闭。从顶角开始,然后转到屏幕中间。

java1:

public class TourmapActivity extends MapActivity {

    private MapView mapView; 

    private MyOverlay myOverlay;

    private List<Overlay> mapOverlays;

    /** Called when the activity is first created. */
     @Override
        public void onCreate(Bundle savedInstanceState) {

            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);

            mapView = (MapView) findViewById(R.id.mapview);       
            mapView.setBuiltInZoomControls(true);


        mapOverlays = mapView.getOverlays();
        myOverlay = new MyOverlay(mapView);
        mapOverlays.add(myOverlay);


    }

    @Override
    protected boolean isRouteDisplayed() {
        // TODO Auto-generated method stub
        return false;
    }
}

Java2的:     公共类MyOverlay扩展了Overlay {

    private Point point1;
    private Point point2;
    private Projection projection;

    public MyOverlay(MapView mapView){
        projection = mapView.getProjection();
    }

    public void draw(Canvas canvas, MapView mapView, boolean shadow){
        super.draw(canvas, mapView, shadow);
        Paint paint = new Paint();
        paint.setDither(true);
        paint.setColor(Color.BLUE);
        paint.setStyle(Paint.Style.FILL_AND_STROKE);
        paint.setStrokeJoin(Paint.Join.ROUND);
        paint.setStrokeCap(Paint.Cap.ROUND);
        paint.setStrokeWidth(2);

        point1 = new Point();
        point2 = new Point();
        Path path = new Path();

       //43.26082327999097, -79.92047309875488 jhe
        float longitude = 43.26082327999097f;   // first point
        float latitude = -79.92047309875488f;

        //43.26347189172956, -79.91776943206787 student center
        float longitude_1 = 43.26347189172956f; // second point
        float latitude_1 = -79.91776943206787f;




        GeoPoint geoPoint1 = new GeoPoint((int)(longitude * 1E6), (int)(latitude * 1E6));
        GeoPoint geoPoint2 = new GeoPoint((int)(longitude_1 * 1E6), (int)(latitude_1* 1E6));


        projection.toPixels(geoPoint1, point1);
        projection.toPixels(geoPoint2, point2);

        path.lineTo(point1.x, point1.y);
        path.lineTo(point2.x, point2.y);

        canvas.drawPath(path, paint);
    }
}

1 个答案:

答案 0 :(得分:0)

您应该查看documentation for Path,特别是lineTomoveTo

所以你要改变

path.lineTo(point1.x, point1.y);

path.moveTo(point1.x, point1.y);