我目前正在做一个包含谷歌地图的安卓应用程序。在这张地图中,我想在两点之间手动绘制一条路径。一个点是我当前的点,另一个是用户标记的点(使用overlay类中的draw方法绘制,代码如下)。请帮助我。
protected class Touchy extends Overlay {
@Override
public boolean draw(Canvas canvas, MapView mapView, boolean shadow,
long when) {
Paint paint = new Paint();
super.draw(canvas, mapView, shadow);
// Converts lat/lng-Point to OUR coordinates on the screen.
Point myScreenCoords = new Point();
mapView.getProjection().toPixels(geoPoint, myScreenCoords);
paint.setStrokeWidth(1);
paint.setARGB(255, 255, 255, 255);
paint.setStyle(Paint.Style.STROKE);
Bitmap bmp = BitmapFactory.decodeResource(getResources(),
R.drawable.source);
canvas.drawBitmap(bmp, myScreenCoords.x, myScreenCoords.y, paint);
for(int i=0;i<size;i++)
{
mapView.getProjection().toPixels(GP[i], myScreenCoords);
canvas.drawBitmap(bmp,myScreenCoords.x, myScreenCoords.y, paint);
}
return true;
}
@Override
public boolean onTouchEvent(MotionEvent e, final MapView m) {
// TODO Auto-generated method stub
System.out.println("Hiiiiiiiiiiiiiiiiiiii");
if (e.getAction() == MotionEvent.ACTION_DOWN) {
start = e.getEventTime();
int x = (int) e.getX();
int y = (int) e.getY();
touchedPoint = m.getProjection().fromPixels(x, y);
System.out.println(touchedPoint);
}
if (e.getAction() == MotionEvent.ACTION_UP) {
stop = e.getEventTime();
}
if (stop - start > 1500) {
AlertDialog alert = new AlertDialog.Builder(
LocationTrackerActivity.this).create();
alert.setTitle("Location Tracker");
alert.setMessage("Enter your Option");
alert.setButton("Mark", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
if (FlagPin == 0) {
OverlayItem overlayItem = new OverlayItem(
touchedPoint, "wazzup", "xd");
PinPoint custom = new PinPoint(d,
LocationTrackerActivity.this);
custom.insertPinpoint(overlayItem);
overlayList.add(custom);
FlagPin = 1;
destLat = touchedPoint.getLatitudeE6() / 1E6;
desLong = touchedPoint.getLongitudeE6() / 1E6;
}
}
});