GoogleMap谷歌地图添加文字覆盖物
Google地图未提供添加纯文字覆盖物接口,可以先将文字加载到Bitmap,再通过MarkerOptions 加载Bitmap,效果一样的
private void addTextToGoogleMap(String textStr
,LatLng latLng
){
Paint mTextPaint
= new Paint();
Rect boundsText
= new Rect();
boundsText
.getTextBounds(textStr
,0,textStr
.length(),boundsText
);
Bitmap
.Config conf
= Bitmap
.Config
.ARGB_8888;
Bitmap bmpText
= Bitmap
.createBitmap(boundsText
.width(),boundsText
.height(),conf
);
Canvas canvasText
= new Canvas(bmpText
);
canvasText
.drawText(textStr
,0,canvasText
.getHeight(),mTextPaint
);
MarkerOptions markerOptions
= new MarkerOptions()
.position(latLng
)
.icon(BitmapDescriptorFactory
.fromBitmap(bmpText
))
.anchor(0.5f
,1);
googleMap
.addMarker(markerOptions
);
}