今まで、マップにマーカーを設定するためにドローアブルを使用していました。カスタム イメージビューをマップにマーカーとして表示できればクールだろうと思っていました。
今まで私はそれをやっています
itemized= new Itemazide(drawable, mContext);
私は何かを達成したい
今まで、マップにマーカーを設定するためにドローアブルを使用していました。カスタム イメージビューをマップにマーカーとして表示できればクールだろうと思っていました。
今まで私はそれをやっています
itemized= new Itemazide(drawable, mContext);
私は何かを達成したい
少し遅れるかもしれませんが、同様の問題に直面している/直面している他の人のために解決策を投稿します. したがって、基本的にあなたがしなければならないことは(少なくともあなたが求めている解決策、つまりボックスのような背景に課されたカスタム画像のために)、キャンバスの助けを借りて背景ボックスに customImage を課すことです。この実装を使用すると、キャンバスから BitmapDrawable を効果的に作成して、「Overlay」/「ItemizedOverlay」のマーカーとして割り当てることができます。また、オーバーレイごとに ImageView を作成しないでください。何千もの ImageView を同時に処理する必要がある場合、メモリやアプリが完全に破壊されます。代わりに、構築中にオーバーレイに割り当てることができ、ImageView として十分なメモリを消費しない BitmapDrawables を使用します。
public BitmapDrawable imageOnDrawable(int drawableBackground, Bitmap customImage)
{
//The following line is optional but I'd advise you to minimize the size of
//the size of the bitmap (using a thumbnail) in order to improve draw
//performance of the overlays (especially if you are creating a lot of overlays).
Bitmap customImageThumbnail = ThumbnailUtils.extractThumbnail(
customImage, 100, 100);
Bitmap bm = BitmapFactory.decodeResource(getResources(), drawableId);
bm = Bitmap.createScaledBitmap(bm, 112, 120, false);
Canvas canvas = new Canvas(bm);
canvas.drawBitmap(bm, 0, 0, null);
// The 6,6 in the below line refer to the offset of the customImage/Thumbnail
// from the top-left corner of the background box (or whatever you want to use
// as your background)
canvas.drawBitmap(customImageThumbnail, 6, 6, null);
return new BitmapDrawable(bm);
}
ええ、私はこのようなことができるかどうか疑問に思っていました。つまりView
、drawable の代わりにカスタムを表示します。メソッドをオーバーライドすることはできますdraw()
が、残念ながら常に (誰かが私が間違っていると教えてください) 描画可能でなければなりません。View
カスタムがメモリを使いすぎるからだと思います。
そうは言っても、達成しようとしていることに応じて、mapview-baloonライブラリをハックして同様の効果を達成することはおそらく可能です。
EDIT:
あなたが達成しようとしていることを示しdraw()
たので、あなたのをオーバーライドしOverlayItem
、このメソッドであなたのを膨らませるべきだと思いますImageView
。しかし、私はこのようにしようとしなかったので、いくつかの欠点があるかもしれません (私は、これですべてのタッチイベントを中断すると主張した同様の問題に関する SO スレッドを覚えていますOverlayItem
)。
In google mapv2, map-view ballon like functionality is provided by default.
Just, you have to write some lines for it :
private GoogleMap mapView;
if (mapView == null)
mapView = ((MapFragment) getFragmentManager().findFragmentById(
R.id.map_view)).getMap();
mapView.getUiSettings().setMyLocationButtonEnabled(false);
mapView.setMyLocationEnabled(true);
MarkerOptions markerDestinationOptions;
markerDestinationOptions = new MarkerOptions()
.position(latLngDestination) .icon(BitmapDescriptorFactory.fromResource(R.drawable.marker));
mapView.addMarker(markerDestinationOptions);