谷歌地图添加文字覆盖物

xiaoxiao2025-04-21  17

GoogleMap谷歌地图添加文字覆盖物

Google地图未提供添加纯文字覆盖物接口,可以先将文字加载到Bitmap,再通过MarkerOptions 加载Bitmap,效果一样的

// An highlighted block 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); //构建options MarkerOptions markerOptions = new MarkerOptions() .position(latLng) .icon(BitmapDescriptorFactory.fromBitmap(bmpText)) .anchor(0.5f,1); googleMap.addMarker(markerOptions); }
转载请注明原文地址: https://www.6miu.com/read-5028750.html

最新回复(0)