Issue
Developing an Android app to draw more than four lines and connect them each to appear that as polygon. Using the angle I find coordinates where to start and end the line, then I draw on mapview. But my need is to, the polygon starts the first line from base(which is horizontal to the device). How to reposition the line? Help me to find a solution..
The image shows my real need..
http://tinypic.com/view.php?pic=rbgoix&s=8#.U8S6NZSSy80
Code:
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;
}
Solution
You can use below code -
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);
Answered By - yuva ツ
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.