我正在制作基于适用于Android的Google地图服务的公共交通地图。地图应包含大量标记(超过300个),并且在地图放大和缩小(缩放)时应调整大小。现在标记只是相互重叠,有没有办法像这样创建自定义标记?
我已经尝试过自己,但没有成功。使用android-map-utils库(https://github.com/googlemaps/android-maps-utils)标记现在看起来更好,但它们不可调整大小并且看起来不同。
标准: - 标记包含指向所需位置的点和位于点右侧或左侧的文本 - 标记应使用地图调整大小。
答案 0 :(得分:1)
使用bitmapscale
Bitmap markerBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.icon_marker,options);
markerBitmap = SubUtils.scaleBitmap(markerBitmap, 70, 70);
然后将其设置为Markeroptions
MarkerOptions marker = new MarkerOptions().icon(BitmapDescriptorFactory.fromBitmap(markerBitmap));
Marker mark = googleMap.addMarker(marker);
这里是scaleBitmap方法
public static Bitmap scaleBitmap(Bitmap bitmap, int newWidth, int newHeight) {
Bitmap scaledBitmap = Bitmap.createBitmap(newWidth, newHeight, Bitmap.Config.ARGB_8888);
float scaleX = newWidth / (float) bitmap.getWidth();
float scaleY = newHeight / (float) bitmap.getHeight();
float pivotX = 0;
float pivotY = 0;
Matrix scaleMatrix = new Matrix();
scaleMatrix.setScale(scaleX, scaleY, pivotX, pivotY);
Canvas canvas = new Canvas(scaledBitmap);
canvas.setMatrix(scaleMatrix);
canvas.drawBitmap(bitmap, 0, 0, new Paint(Paint.FILTER_BITMAP_FLAG));
return scaledBitmap;
}