Android: How to set image as marker in google map API?

so far i have used drawable to fill the marker on my map. Now I wondered if it would be cool if I could display a custom image as a marker on a map.

still i do it like

      itemized= new Itemazide(drawable, mContext);

I want to achieve something like

this

+5
source share
3 answers

Yes, I was wondering if I can do something like this, i.e. show custom Viewinstead of drawable. You can override the method draw(), but unfortunately, it always (someone, tell me that I'm wrong) should be available. I think because custom Viewtakes up too much memory.

, , , , mapview-baloon, .

EDIT: , , , , draw() OverlayItem ImageView. , ( SO , , OverlayItem).

+1

, , , . , , ( , , , , ) customImage . , BitmapDrawable , "Overlay" / "ItemizedOverlay". , , ImageView , / , ImageViews . BitmapDrawables, ImageView.

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);

}
+2
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);
+1
source

All Articles