How can I create a speech-bubble border for a Google Marker Custom Icon using Picasso?

前端 未结 3 680
后悔当初
后悔当初 2020-12-06 02:27

How can I use Picasso and Google Marker Custom Icon to achieve this feature?

I know how to use Picasso for the image, but I don\'t know how to add that \"ma

3条回答
  •  醉梦人生
    2020-12-06 02:56

    You can set in kotlin like this..

      override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
            super.onViewCreated(view, savedInstanceState)
    
    
            mapView.getMapAsync { googleMap ->
                googleMap1 = googleMap as GoogleMap
                addCustomMarker()
            }
    
        }
    
    
     private fun addCustomMarker() {
            Log.d("addCustomMarker", "addCustomMarker()")
            if (googleMap1 == null) {
                return
            }
            // adding a marker on map with image from  drawable
            googleMap1.addMarker(
                MarkerOptions()
                    .position(LatLng(23.0225 , 72.5714))
                    .icon(BitmapDescriptorFactory.fromBitmap(getMarkerBitmapFromView()))
            )
        }
    
    
    
        private fun getMarkerBitmapFromView(): Bitmap? {
            val customMarkerView: View? = layoutInflater.inflate(R.layout.view_custom_marker, null)
    //        val markerImageView: ImageView =
    //            customMarkerView.findViewById(R.id.profile_image) as ImageView
            customMarkerView?.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED );
            customMarkerView?.layout(0, 0, customMarkerView.measuredWidth, customMarkerView.measuredHeight);
            customMarkerView?.buildDrawingCache();
            val returnedBitmap = Bitmap.createBitmap(
                customMarkerView!!.measuredWidth, customMarkerView.measuredHeight,
                Bitmap.Config.ARGB_8888
            )
            val canvas = Canvas(returnedBitmap)
            canvas.drawColor(Color.WHITE, PorterDuff.Mode.SRC_IN)
            val drawable = customMarkerView.background
    
            drawable?.draw(canvas);
            customMarkerView.draw(canvas);
            return returnedBitmap;
    
        }
    

提交回复
热议问题