マップの追加方法は、マップのオフライン領域選択画面のように画面の幅80%、高さ80%を表す四角形をマップに追加する方法です。この矩形のLatLngBoundを取得する必要があります.LinearLayoutはここでの解決策ではないかもしれません。固定(ズーム独立)長方形Googleマップ
0
A
答えて
1
あなたはgetProjection()
方法により、画素のLatLon
座標を取得し、あなたがcustom viewのonDraw()
方法にしたいすべてのものを描くことができます。だから、
、NSimonのthis答えにちょうどあなたのマップアクティビティのレイアウトXMLでMapFragment
上で必要な透明性とカスタムビュー(例えばFrameView
)を追加よう:
<fragment
android:id="@+id/map_fragment"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<[your_package].FrameView
android:id="@+id/frame_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
[your_package].FrameView
をis
public class FrameView extends View {
private Paint mTransparentPaint;
private Paint mBorderPaint;
private Paint mSemiBlackPaint;
private Path mPath = new Path();
private GoogleMap mGoogleMap = null;
private float x1, y1, x2, y2;
public FrameView(Context context) {
super(context);
init();
}
public FrameView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public FrameView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}
private void init() {
mTransparentPaint = new Paint();
mTransparentPaint.setColor(Color.TRANSPARENT);
mTransparentPaint.setStyle(Paint.Style.FILL);
mBorderPaint = new Paint();
mBorderPaint.setColor(Color.BLUE);
mBorderPaint.setStyle(Paint.Style.STROKE);
mBorderPaint.setStrokeWidth(10);
mSemiBlackPaint = new Paint();
mSemiBlackPaint.setColor(Color.TRANSPARENT);
mSemiBlackPaint.setStyle(Paint.Style.FILL);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
x1 = 0.1f * canvas.getWidth();
y1 = 0.1f * canvas.getHeight();
x2 = 0.9f * canvas.getWidth();
y2 = 0.8f * canvas.getHeight();
mPath.reset();
mPath.addRect(x1, y1, x2, y2, Path.Direction.CW);
mPath.setFillType(Path.FillType.INVERSE_EVEN_ODD);
canvas.drawRect(x1, y1, x2, y2, mTransparentPaint);
canvas.drawRect(x1, y1, x2, y2, mBorderPaint);
canvas.drawPath(mPath, mSemiBlackPaint);
canvas.clipPath(mPath);
canvas.drawColor(Color.parseColor("#83000000"));
}
public void setMap(GoogleMap googleMap) {
mGoogleMap = googleMap;
}
public LatLng getTopLeft() {
return point2LatLng(new Point((int)x1, (int)y1));
}
public LatLng getTopRight() {
return point2LatLng(new Point((int)x2, (int)y1));
}
public LatLng getBottomLeft() {
return point2LatLng(new Point((int)x1, (int)y2));
}
public LatLng getBottomRight() {
return point2LatLng(new Point((int)x2, (int)y2));
}
public LatLng point2LatLng(Point point) {
if (mGoogleMap != null) {
Projection projection = mGoogleMap.getProjection();
return projection.fromScreenLocation(point);
} else {
return null;
}
}
}
ここで、x1、x2、y1、y2 - "frame"矩形のピクセル単位の座標。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mFrameView = (FrameView) findViewById(R.id.frame_view);
mapFragment = (MapFragment) getFragmentManager()
.findFragmentById(R.id.map_fragment);
mapFragment.getMapAsync(this);
...
}
とonMapReady()
にmFrameView
ためGoogleMap
オブジェクトを設定します:あなたはonCreate()
でFrameView
オブジェクトを取得必要以上
@Override
public void onMapReady(GoogleMap googleMap) {
mGoogleMap = googleMap;
mFrameView.setMap(mGoogleMap);
...
}
、今あなたがmFrameView.getTopLeft()
でLatLon
COORDSを得ることができますが、mFrameView.getTopRight()
などのコール必要なときに:
NB!これはカスタムコンポーネントの素早く汚れた例です。
関連する問題
- 1. 固定長方形の長方形パッキング
- 2. Googleマップから長方形を削除
- 3. 固定ヘッダーはGoogleマップ
- 4. Android Googleマップ、ポリライン、ズーム
- 5. 最大の「ズーム」を持つ円の内側にある固定長の長方形をパックする
- 6. Googleマップを動的にズーム
- 7. マウス(Googleマップなど)にズーム
- 8. 長方形内の場所を取得するGoogleマップ
- 9. 独立したスクロールdiv、固定ヘッダーとフッターを持つもの
- 10. 独立したスクロールバーを持つ固定位置のサイドバー?
- 11. LPによる線形独立性テスト
- 12. D3:独立したズーム動作の2つのx軸
- 13. Libgdxは - 長方形/ライン(shaperenderer)をズームする方法を
- 14. Googleマップ地形のデフォルト設定では
- 15. 固定長ハッシュ
- 16. Googleマップのズーム変更リスナーapi 2
- 17. Googleマップのマーカーのドラッグ&ズームの問題
- 18. GoogleマップAPIのジェスチャーは(ズーム・回転...)
- 19. アンドロイドでGoogleマップのズーム範囲を定義しました
- 20. パン&ズーム軸の長方形のサイズを変更
- 21. Googleマップv2 - 自分の位置とズームの両方を設定します
- 22. SQLテーブル内の固定された数の反復独立オブジェクトの表現
- 23. XSLパディング固定長
- 24. 平均固定長が同じ固定長
- 25. Googleマップのダブルタップでセンターをズームする方法アンドロイドスタジオのフラグメント
- 26. 独立した不安定な独立したアニメーションに反応しますか?
- 27. 独立エンティティは春データに固執する渡さ
- 28. マルチスレッド独立タスク
- 29. 独立ダブルピッカー
- 30. 固定小数点をズームするMapBoxズーム動作
getProjection()は私が逃した部分でした...完璧なサウンド!なぜあなたは「素早く汚い」と言いますか? – Daminox
@Daminox 'FrameView'と' GoogleMap'は1つのコンポジットカスタムビューでなければならないので、 'setMap()'は動作しますが、とても良い方法ではありません。そして、すべての 'point2LatLng()'呼び出しと ''#83000000 "'に新しい 'Point'オブジェクトを作成する必要はありません - 青い矩形の周りの暗い枠など: –
MapFragmentではなく、カスタムフラグメントを使用してください。そうですか? – Daminox