public class Route_mapActivity extends MapActivity {
/** Called when the activity is first created. */
private List mapOverlays;
private Projection projection;
private MapController mc;
private MapView mapView;
private GeoPoint gP;
// private GeoPoint gP2;
private MyOverlay myoverlay;
double my_Latitude, friend_latitude;
double my_Longitude, friend_Longitude;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mapview);
mapView = (MapView) findViewById(R.id.mapview);// Creating an instance
// of MapView
mapView.setBuiltInZoomControls(true);// Enabling the built-in Zoom
// Controls
gP = new GeoPoint(33695043, 73000000);// Creating a GeoPoint
mc = mapView.getController();
mc.setCenter(gP);
mc.setZoom(9);// Initializing the MapController and setting the map to
// center at the
// defined GeoPoint
mapOverlays = mapView.getOverlays();
projection = mapView.getProjection();
myoverlay = new MyOverlay();
mapOverlays.add(myoverlay);
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
class MyOverlay extends Overlay {
public MyOverlay() {
}
public void draw(Canvas canvas, MapView mapv, boolean shadow) {
super.draw(canvas, mapv, shadow);
// Configuring the paint brush
Point screenPts = new Point();
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(4);
my_Latitude = getIntent().getExtras().getDouble("my_Latitude");
my_Longitude = getIntent().getExtras().getDouble("my_Longitude");
friend_latitude = getIntent().getExtras().getDouble("friend_lati");
friend_Longitude = getIntent().getExtras().getDouble("friend_longni");
Log.e("my_Latitude1E6", "" + ((int) (my_Latitude * 1000000)));
GeoPoint gP1 = new GeoPoint((int) (my_Latitude * 1000000),
((int) my_Longitude * 1000000));// starting point Abbottabad
GeoPoint gP2 = new GeoPoint(
(int) (friend_latitude * 1000000 + 1000000),
((int) friend_Longitude * 1000000 + 1000000));// End point
// Islamabad
Point p1 = new Point();
Point p2 = new Point();
Path path1 = new Path();
Point p3 = new Point();
Point p4 = new Point();
Path path2 = new Path();
projection.toPixels(gP2, p3);
projection.toPixels(gP1, p4);
path1.moveTo(p4.x, p4.y);// Moving to Abbottabad location
path1.lineTo(p3.x, p3.y);// Path till Islamabad
/*
* projection.toPixels(gP3, p1);
*
* projection.toPixels(gP4, p2);
*/
path2.moveTo(p2.x, p2.y);// Moving to Islamabad location
path2.lineTo(p1.x, p1.y);// Path to Rawalpindi
canvas.drawPath(path1, mPaint);// Actually drawing the path from
// Abbottabad to Islamabad
canvas.drawPath(path2, mPaint);// Actually drawing the path from
// Islamabad to Rawalpindi
}
}
}
No comments:
Post a Comment