在mapview上重绘绘制的线条

时间:2014-07-15 05:18:06

标签: android line coordinates android-mapview

开发Android应用程序以绘制超过四行并将它们连接起来以将其显示为多边形。使用角度我找到坐标从哪里开始和结束线,然后我在mapview上绘制。但我需要的是,多边形从基线(水平到设备)开始第一条线。如何重新定位线?帮我找一个解决方案..

图像显示了我真正的需要......

http://tinypic.com/view.php?pic=rbgoix&s=8#.U8S6NZSSy80

代码:

 m=0;
 x[m]= (dis[m]*1000)*Math.sin((angle1[m])*Math.PI / 180);
 y[m]= (dis[m]*1000)*Math.cos((angle1[m])*Math.PI / 180);
 GeoPoint g = new GeoPoint((int)(x[m]),(int)(y[m]));
 Point p=new Point();
 projection.toPixels(g, p);
 Path path=new Path();
    l=pp.x;
    o=pp.y;

for( m=1;m<j+1;m++)  
{   
 x[m]= (dis[m]*1000)*Math.sin((angle1[m])*Math.PI / 180);
 y[m]= (dis[m]*1000)*Math.cos((angle1[m])*Math.PI / 180);
 GeoPoint g1 = new GeoPoint((int)(x[m]),(int)(y[m]));
 Point p1=new Point();
 projection.toPixels(g1, p1);
 Path path1=new Path(); 
if(m!=j)
 {
 path1.moveTo(p.x, p.y);
 path1.lineTo(p1.x, p1.y);
 canvas.drawPath(path1, mPaint);
    lPaint.setTextAlign(Paint.Align.CENTER);
    canvas.drawTextOnPath((sf.format(distance[m-1])).toString()+" ,"+m+" ,"+v[m], path1,10 ,20, lPaint);
}
else
{
p1.x=l;
p1.y=o;
path1.moveTo(p1.x, p1.y);
path1.lineTo(pp.x, pp.y);
canvas.drawPath(path1, mPaint);
    lPaint.setTextAlign(Paint.Align.CENTER);
    canvas.drawTextOnPath((sf.format(distance[m-1])).toString()+" ,"+m, path1,10 ,20, lPaint);
}
//Toast.makeText(getApplicationContext(),"Angle"+distance[m], Toast.LENGTH_SHORT).show();
    p.x=p1.x;
    p.y=p1.y;   

}

1 个答案:

答案 0 :(得分:0)

您可以使用以下代码 -

            ArrayList<LatLng> points = null;
            // Traversing through all the routes
            for(int i=0;i<result.size();i++){
                points = new ArrayList<LatLng>();
                lineOptions = new PolylineOptions();
                // Fetching i-th route
                List<HashMap<String, String>> path = result.get(i);

                // Fetching all the points in i-th route
                for(int j=0;j<path.size();j++){
                    HashMap<String,String> point = path.get(j);                 
                    // Here add your latitude & longitude of locations
                    /*double lat = Double.parseDouble(point.get("lat"));
                    double lng = Double.parseDouble(point.get("lng"));
                    LatLng position = new LatLng(lat, lng); */
                    points.add(position);                       
                }

                // Adding all the points in the route to LineOptions
                lineOptions.addAll(points);
                lineOptions.width(5);
                lineOptions.color(Color.BLUE);  

            }
            map.addPolyline(lineOptions);