I am trying to create a custom marker that displays text with a number equal to the example below:
Example:

But when you start the application, the text is not displayed, only a red ellipse appears without a number.
My code
InicializeMap () ##
private void InicializeMap() { if (_googleMap == null) { _googleMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.mapMapeamento)).getMap(); LatLng pos = new LatLng(23.4555453556, 11.145315551); MapUtils mapUtils = new MapUtils(getApplicationContext()); Bitmap bitmap = mapUtils.GetBitmapMarker(); Marker marker = _googleMap.addMarker(new MarkerOptions() .position(pos) .icon(BitmapDescriptorFactory.fromBitmap(bitmap))); // check if map is created successfully or not if (_googleMap == null) Toast.makeText(getApplicationContext(), Mensagens.erroCriarMapa, Toast.LENGTH_SHORT).show(); } }
My bitmap creation method
public Bitmap GetBitmapMarker() { Paint color = new Paint(); color.setTextSize(35); color.setColor(Color.BLACK); int px = _mContext.getResources().getDimensionPixelSize(R.dimen.map_dot_marker_size); Bitmap mDotMarkerBitmap = Bitmap.createBitmap(px, px, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(mDotMarkerBitmap); canvas.drawText("Hello!", 30, 40, color); Drawable shape = _mContext.getResources().getDrawable(R.drawable.shape_marker_red); shape.setBounds(0, 0, mDotMarkerBitmap.getWidth(), mDotMarkerBitmap.getHeight()); shape.draw(canvas); return mDotMarkerBitmap; }
Res / draw / shape_marker_red
<?xml version="1.0" encoding="utf-8"?>
<gradient android:angle="90" android:endColor="#f58383" android:startColor="#ee6464" /> <stroke android:width="1dp" android:color="#a13939" />
android google-maps google-maps-markers
Renan barbosa
source share