adding onTap method on path direction between 2 point
Posted
by
idham
on Stack Overflow
See other posts from Stack Overflow
or by idham
Published on 2012-07-07T16:57:41Z
Indexed on
2012/07/08
3:15 UTC
Read the original article
Hit count: 355
I have a problem in my Android application
I have a path direction on my application and I want to add an onTap method for the path, so if I touch that path my application will display information with alert dialog.
This my activity code:
hasilrute hr = new hasilrute();
for (int k = 0;k < hr.r2.size(); k++){
String angkot = hr.r2.get(i).angkot;
Cursor c = db.getLatLong(hasilrute.a);
Cursor cc = db.getLatLong(hasilrute.b);
String x = (c.getString(3)+","+c.getString(2));
String xx = (cc.getString(3)+","+cc.getString(2));
String pairs[] = getDirectionData(x, xx);
String[] lnglat = pairs[0].split(",");
GeoPoint point = new GeoPoint((int) (Double.parseDouble(lnglat[1]) *1E6),(int)(Double.parseDouble(lnglat[0]) * 1E6));
GeoPoint gp1;
GeoPoint gp2 = point;
for (int j = 1;j < pairs.length; j++){
lnglat = pairs[j].split(",");
gp1 = gp2;
gp2 = new GeoPoint((int) (Double.parseDouble(lnglat[1]) *1E6),(int) (Double.parseDouble(lnglat[0]) * 1E6));
mapView.getOverlays().add(new jalur(gp1, gp2,angkot));
}
}
and it's my jalur.java code
public class jalur extends Overlay {
private GeoPoint gp1;
private GeoPoint gp2;
private String angkot;
private Context mContext;
public jalur(GeoPoint gp1, GeoPoint gp2, String angkot){
this.gp1 = gp1;
this.gp2 = gp2;
this.angkot = angkot;
}
@Override
public boolean draw(Canvas canvas, MapView mapView,
boolean shadow, long when){
Projection projection = mapView.getProjection();
if (shadow == false){
if (angkot.equals("Cimahi-Leuwipanjang")){
Paint paint = new Paint();
paint.setAntiAlias(true);
Point point = new Point();
projection.toPixels(gp1,point);
Point point2 = new Point();
projection.toPixels(gp2, point2);
paint.setColor(Color.rgb(118,171,127));
paint.setStrokeWidth(2);
canvas.drawLine((float) point.x, (float) point.y, (float) point2.x,
(float) point2.y, paint);
}if (angkot.equals("Cimahi-Cangkorah")){
Paint paint = new Paint();
paint.setAntiAlias(true);
Point point = new Point();
projection.toPixels(gp1,point);
Point point2 = new Point();
projection.toPixels(gp2, point2);
paint.setColor(Color.rgb(67,204,255));
paint.setStrokeWidth(2);
canvas.drawLine((float) point.x, (float) point.y, (float) point2.x,
(float) point2.y, paint);
}if (angkot.equals("Cimindi-Cipatik")){
Paint paint = new Paint();
paint.setAntiAlias(true);
Point point = new Point();
projection.toPixels(gp1,point);
Point point2 = new Point();
projection.toPixels(gp2, point2);
paint.setColor(Color.rgb(42,82,0));
paint.setStrokeWidth(2);
canvas.drawLine((float) point.x, (float) point.y, (float) point2.x,
(float) point2.y, paint);
}if (angkot.equals("Jalan Kaki")){
Paint paint = new Paint();
paint.setAntiAlias(true);
Point point = new Point();
projection.toPixels(gp1,point);
Point point2 = new Point();
projection.toPixels(gp2, point2);
paint.setColor(Color.rgb(0,0,0));
paint.setStrokeWidth(2);
canvas.drawLine((float) point.x, (float) point.y, (float) point2.x,
(float) point2.y, paint);
}if (angkot.equals("Cimahi-Padalarang")){
Paint paint = new Paint();
paint.setAntiAlias(true);
Point point = new Point();
projection.toPixels(gp1,point);
Point point2 = new Point();
projection.toPixels(gp2, point2);
paint.setColor(Color.rgb(229,66,66));
paint.setStrokeWidth(2);
canvas.drawLine((float) point.x, (float) point.y, (float) point2.x,
(float) point2.y, paint);
}
if (angkot.equals("Pasantren-Sarijadi")){
Paint paint = new Paint();
paint.setAntiAlias(true);
Point point = new Point();
projection.toPixels(gp1,point);
Point point2 = new Point();
projection.toPixels(gp2, point2);
paint.setColor(Color.rgb(4,39,255));
paint.setStrokeWidth(2);
canvas.drawLine((float) point.x, (float) point.y, (float) point2.x,
(float) point2.y, paint);
}if (angkot.equals("Cimahi-Parongpong")){
Paint paint = new Paint();
paint.setAntiAlias(true);
Point point = new Point();
projection.toPixels(gp1,point);
Point point2 = new Point();
projection.toPixels(gp2, point2);
paint.setColor(Color.rgb(141,0,200));
paint.setStrokeWidth(2);
canvas.drawLine((float) point.x, (float) point.y, (float) point2.x,
(float) point2.y, paint);
}if (angkot.equals("Cimahi-Cibeber")){
Paint paint = new Paint();
paint.setAntiAlias(true);
Point point = new Point();
projection.toPixels(gp1,point);
Point point2 = new Point();
projection.toPixels(gp2, point2);
paint.setColor(Color.rgb(255,246,0));
paint.setStrokeWidth(2);
canvas.drawLine((float) point.x, (float) point.y, (float) point2.x,
(float) point2.y, paint);
}if (angkot.equals("Cimahi-Cimindi")){
Paint paint = new Paint();
paint.setAntiAlias(true);
Point point = new Point();
projection.toPixels(gp1,point);
Point point2 = new Point();
projection.toPixels(gp2, point2);
paint.setColor(Color.rgb(220,145,251));
paint.setStrokeWidth(2);
canvas.drawLine((float) point.x, (float) point.y, (float) point2.x,
(float) point2.y, paint);
}if (angkot.equals("Cimahi-Contong")){
Paint paint = new Paint();
paint.setAntiAlias(true);
Point point = new Point();
projection.toPixels(gp1,point);
Point point2 = new Point();
projection.toPixels(gp2, point2);
paint.setColor(Color.rgb(242,138,138));
paint.setStrokeWidth(2);
canvas.drawLine((float) point.x, (float) point.y, (float) point2.x,
(float) point2.y, paint);
}if (angkot.equals("Cimahi-Soreang")){
Paint paint = new Paint();
paint.setAntiAlias(true);
Point point = new Point();
projection.toPixels(gp1,point);
Point point2 = new Point();
projection.toPixels(gp2, point2);
paint.setColor(Color.rgb(0,255,78));
paint.setStrokeWidth(2);
canvas.drawLine((float) point.x, (float) point.y, (float) point2.x,
(float) point2.y, paint);
}if (angkot.equals("Cimahi-Batujajar")){
Paint paint = new Paint();
paint.setAntiAlias(true);
Point point = new Point();
projection.toPixels(gp1,point);
Point point2 = new Point();
projection.toPixels(gp2, point2);
paint.setColor(Color.rgb(137,217,51));
paint.setStrokeWidth(2);
canvas.drawLine((float) point.x, (float) point.y, (float) point2.x,
(float) point2.y, paint);
}
}
return super.draw(canvas, mapView, shadow, when);
}
@Override
public void draw(Canvas canvas, MapView mapView, boolean shadow){
super.draw(canvas, mapView, shadow);
}
}
thanks for your attention :)
© Stack Overflow or respective owner