[英]Google maps custom marker android
I'm making a public transportation map based on Google Maps service for Android. 我正在基于Android的Google Maps服务制作一张公共交通地图。 The map should contain a lot of markers (over 300) and they should resize when the map is zooming in and out (scale).
地图应包含许多标记(超过300个),并且在地图放大和缩小(缩放)时应调整其大小。 Right now the markers just overlap each other, is there a way to create custom markers like this?
现在,标记只是彼此重叠,有没有办法创建这样的自定义标记?
I have tried myself, but have had no success. 我已经尝试过自己,但没有成功。 With android-map-utils library ( https://github.com/googlemaps/android-maps-utils ) markers now look better, but they aren't resizeable and look different.
有了android-map-utils库( https://github.com/googlemaps/android-maps-utils ),标记现在看起来更好了,但是它们不可调整大小且看起来不同。
Criteria: - Markers contain a dot that points on needed location and text on right or left side of dot - Markers should resize with map. 准则:-标记包含一个点,该点指向所需的位置,文本位于该点的右侧或左侧-标记应随地图调整大小。
using bitmapscale 使用位图比例
Bitmap markerBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.icon_marker,options);
markerBitmap = SubUtils.scaleBitmap(markerBitmap, 70, 70);
then set it to your Markeroptions 然后将其设置为您的Markeroptions
MarkerOptions marker = new MarkerOptions().icon(BitmapDescriptorFactory.fromBitmap(markerBitmap));
Marker mark = googleMap.addMarker(marker);
here is scaleBitmap method 这是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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.