public static BitmapDescriptor getBitmapFromView(View view) { view.destroyDrawingCache(); view.measure( View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight()); view.setDrawingCacheEnabled(true); Bitmap bitmap = view.getDrawingCache(true); BitmapDescriptor bd = BitmapDescriptorFactory.fromBitmap(bitmap); return bd; }
/** * er for a Cluster is added to the map. Called before the mark The default implementation draws a * circle with a rough count of the number of items. */ protected void onBeforeClusterRendered(Cluster<T> cluster, MarkerOptions markerOptions) { int bucket = getBucket(cluster); BitmapDescriptor descriptor = mIcons.get(bucket); if (descriptor == null) { mColoredCircleBackground.getPaint().setColor(getColor(bucket)); descriptor = BitmapDescriptorFactory.fromBitmap(mIconGenerator.makeIcon(getClusterText(bucket))); mIcons.put(bucket, descriptor); } // TODO: consider adding anchor(.5, .5) (Individual markers will overlap more often) markerOptions.icon(descriptor); }
private void locateOtherLocation(UserShakeData userShakeData, int index) { LatLng cenpt = new LatLng(userShakeData.getLatitude(), userShakeData.getLongitude()); String sex = userShakeData.getSex(); TextView view = new TextView(myContext); view.setTextColor(Color.WHITE); view.setTextSize(15); view.setGravity(Gravity.CENTER_HORIZONTAL); view.setText(String.valueOf(index + 1)); if (sex.equals("female")) view.setBackgroundResource(R.drawable.lj_map_female_location); else view.setBackgroundResource(R.drawable.lj_map_male_location); BitmapDescriptor markIcon = BitmapDescriptorFactory.fromBitmap(getBitmapFromView(view)); OverlayOptions option = new MarkerOptions().position(cenpt).icon(markIcon); Marker marker = (Marker) myContext.baiduMap.addOverlay(option); Bundle bundle = new Bundle(); bundle.putSerializable("index", index); marker.setExtraInfo(bundle); }
private void addlayout(String lat, String lng, String name, String adress, String phone) { LatLng ll = new LatLng(Double.parseDouble("" + lat) - 0.00005, Double.parseDouble("" + lng) - 0.00005); View view2 = LayoutInflater.from(mContext).inflate(R.layout.over_map, null); ((TextView) view2.findViewById(R.id.hospital_name)).setText("医院:" + name); ((TextView) view2.findViewById(R.id.adress)).setText("地址:" + adress); ((TextView) view2.findViewById(R.id.phone)) .setText("距离:" + Float.parseFloat(phone) / 1000 + "km"); BitmapDescriptor bdA = BitmapDescriptorFactory.fromBitmap(textTobimap(view2)); OverlayOptions ooA = new MarkerOptions().position(ll).icon(bdA).zIndex(9).draggable(true); mBaiduMap.addOverlay(ooA); LatLng point = new LatLng(Double.parseDouble("" + lat), Double.parseDouble("" + lng)); // 构建Marker图标 BitmapDescriptor bitmap = BitmapDescriptorFactory.fromResource(R.drawable.icon_marka); // 构建MarkerOption,用于在地图上添加Marker OverlayOptions option = new MarkerOptions().position(point).icon(bitmap); // 在地图上添加Marker,并显示 mBaiduMap.addOverlay(option); }