Set Image from drawable as marker in Google Map version 2

前端 未结 4 1186
难免孤独
难免孤独 2020-12-23 12:59

I am using this part of code to add a marker in a MapFragment in Google Map Version 2.

MarkerOptions op = new MarkerOptions();
op.position(point         


        
4条回答
  •  萌比男神i
    2020-12-23 14:00

    If you have Drawable created programatically (so you have no resource for it), you can use this:

    Drawable d = ... // programatically create drawable
    Canvas canvas = new Canvas();
    Bitmap bitmap = Bitmap.createBitmap(d.getIntrinsicWidth(), d.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
    canvas.setBitmap(bitmap);
    d.draw(canvas);
    BitmapDescriptor bd = BitmapDescriptorFactory.fromBitmap(bitmap);
    

    Then you have BitmapDescriptor, which you can pass into MarkerOptions.

提交回复
热议问题