大佬教程收集整理的这篇文章主要介绍了android – Google Maps v2 Custom Tile Provider,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我的自定义磁贴提供程序类是
public class PolylineTileProvider implements TileProvider { private static final String TAG = "TiLeoverlay"; private final int mTileSize = 256; private final SphericalMercatorProjection mProjection = new SphericalMercatorProjection(mTileSizE); private final int mScale = 2; private final int mDimension = mScale * mTileSize; private final List<PolylineOptions> polylines; public PolylineTileProvider(List<PolylineOptions> polylines) { this.polylines = polylines; } @Override public Tile getTile(int x,int y,int zoom) { Matrix matrix = new Matrix(); float scale = ((float) Math.pow(2,zoom) * mScalE); matrix.postScale(scale,scalE); matrix.postTranslate(-x * mDimension,-y * mDimension); Bitmap bitmap = Bitmap.createBitmap(mDimension,mDimension,Bitmap.Config.ARGB_8888); //save memory on old phones Canvas c = new Canvas(bitmap); c.setMatrix(matriX); drawCanvasFromArray(c,scalE); ByteArrayOutputStream baos = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG,100,baos); return new Tile(mDimension,baos.toByteArray()); } private void drawCanvasFromArray(Canvas c,float scalE) { Paint paint = new Paint(); paint.setAntiAlias(true); paint.setStyle(Paint.Style.stroke); paint.setstrokeCap(Paint.Cap.ROUND); paint.setstrokeJoin(Paint.Join.ROUND); paint.setShadowLayer(0,0); paint.setAntiAlias(true); if (polylines != null) { for (int i = 0; i < polylines.size(); i++) { List<LatLng> route = polylines.get(i).getPoints(); paint.setColor(polylines.get(i).getColor()); paint.setstrokeWidth(getLineWidth(polylines.get(i).getWidth(),scalE)); Path path = new Path(); if (route != null && route.size() > 1) { Point screenPt1 = mProjection.toPoint(route.get(0)); //first point MarkerOptions m = new MarkerOptions(); m.position(route.get(0)); path.moveTo((float) screenPt1.x,(float) screenPt1.y); for (int j = 1; j < route.size(); j++) { Point screenPt2 = mProjection.toPoint(route.get(j)); path.lineTo((float) screenPt2.x,(float) screenPt2.y); } } c.drawPath(path,paint); } } } private float getLineWidth(float width,float scalE) { return width / (scalE); } }
Trafic图层在Google Maps android应用程序中显示得非常好.
我怎样才能制作一个类似的图层.提前致谢.
以上是大佬教程为你收集整理的android – Google Maps v2 Custom Tile Provider全部内容,希望文章能够帮你解决android – Google Maps v2 Custom Tile Provider所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。