オーバーレイを実装して複数のサブクラスを作成できます。現在の場所は固定されており、onclick などのイベントは実行できないと思います。現在の場所のみを表示および維持する 1 つのクラス。
それでは、場所を選択してください。わかりました、そのピンの場所の場所を変更したいと思います。そのために onTap を実装できるので、onTouch() メソッドを使用して、マップの down、move、up イベントを実装できます。マップをタップすると、その位置が取得され、この位置の値が画面 x、y に変換されるとします。その場所に配置するピンに値を追加します。
ここでは、ユーザーがマップをタップしたときにピンをマップに配置するために、このように実装しています
public boolean onTouchEvent(MotionEvent event, final MapView mapView) {
final int action=event.getAction();
final int x=(int)event.getX();
final int y=(int)event.getY();
result = false;
if (action==MotionEvent.ACTION_DOWN) {
downPressed = true;
drag = false;
result = false;
}else if (action==MotionEvent.ACTION_MOVE) {
downPressed = false;
drag=true;
}else if (action==MotionEvent.ACTION_UP) {
if(downPressed){
if(task.equals(SINGLE_LOCATION) | isDirectionPoint | mapView.isStreetView()){
tempPoint = mapView.getProjection().fromPixels(x, y);
mapView.invalidate();
}
}
drag = false;
downPressed = false;
}
return(result | super.onTouchEvent(event, mapView));
}
これが draw() メソッドで呼び出された私の描画メソッドです
private void drawFreeMarker(Canvas canvas, MapView mapView, boolean shadow) {
Point screenPts = new Point();
mapView.getProjection().toPixels(tempPoint, screenPts);
//---add the marker---
Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.bluepin_38);
canvas.drawBitmap(bmp, screenPts.x-((xCurLocOffset/2)-1), screenPts.y-(yCurLocOffset-1), null);
}