で使用されるポリゴン
fram_map.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
float x = event.getX();
float y = event.getY();
int x_co = Math.round(x);
int y_co = Math.round(y);
projection = mMap.getProjection();
Point x_y_points = new Point(x_co, y_co);
LatLng latLng = mMap.getProjection().fromScreenLocation(x_y_points);
latitude = latLng.latitude;
longitude = latLng.longitude;
int eventaction = event.getAction();
switch (eventaction) {
case MotionEvent.ACTION_DOWN:
// finger touches the screen
val.add(new LatLng(latitude, longitude));
case MotionEvent.ACTION_MOVE:
// finger moves on the screen
val.add(new LatLng(latitude, longitude));
case MotionEvent.ACTION_UP:
// finger leaves the screen
Draw_Map();
break;
}
if (Is_MAP_Moveable == true) {
return true;
} else {
return false;
}
}
});
public void Draw_Map() {
rectOptions = new PolygonOptions();
rectOptions.addAll(val);
rectOptions.strokeColor(Color.BLUE);
rectOptions.strokeWidth(7);
rectOptions.fillColor(Color.CYAN);
polygon = mMap.addPolygon(rectOptions);
}
を描く方法です例えば、最初のものの最後のLatLngとして形状設定を閉じる必要があります。
ACTION_DOWNを実行したときに取得されたLatLngへの参照を追加するリスナーを編集し、ACTION_UPを実行するときに以前に参照されたポイントと同じ座標で新しいLatLngを挿入する必要があります。
ハッピーコーディング!
これも試しましたが、ポリゴンは正しく塗りつぶされません。私は何をすべきか? –
@AhmadVataniあなたの描画ポリゴンに交差点がありますか?なぜなら、交差点があるとポリゴンは塗りつぶされません(ドキュメンテーションでは見つかりませんが、一部のデバイスでは経験されます)。 –
はい。解決策はありますか? –