Search code examples
androidandroid-maps-v2

How to make marker with image and text for Map API v2


How to get customize markers with Imageview and Textview for google map v2 for android

Please refer to the attached image for better understanding:


Solution

  • Create a view using XML

    <FrameLayout 
         android:id="@+id/framelayout"
         android:layout_height="wrap_content" 
         android:layout_width="wrap_content">
    
         <ImageView 
              android:id="@+id/ImageView01"
              android:layout_height="wrap_content" 
              android:layout_width="wrap_content"/>
    
        <TextView android:id="@+id/text_view"
              android:layout_width="wrap_content" 
              android:layout_height="wrap_content"/>
    
    </FrameLayout>
    

    Get the view and set your values

    FrameLayout view = (FrameLayout)findViewById(R.id.framelayout);
    

    Generate a bitmap

    view.setDrawingCacheEnabled(true);
    view.buildDrawingCache();
    Bitmap bm = view.getDrawingCache();
    

    use this bitmap as your marker

    Marker myMarker = mMap.addMarker(new MarkerOptions()
       .position(0,0)
       .icon(BitmapDescriptorFactory.fromBitmap(mybitmap)));