문제

How to make custom view for marker or how to make custom layout. like this... enter image description here and please look at screenshot:

enter image description here

도움이 되었습니까?

해결책

I don't code android yet, so this is based largely on the last code block here: http://code.google.com/apis/maps/articles/android_v3.html

Where it ends up being just a regular map implementation, so you'd do the following to add a marker to an existing map:

var myIcon=new google.maps.MarkerImage('my_icon.png');
var point=new google.maps.LatLng(someLatitude,someLongitude);
var marker = new google.maps.Marker({position: point,map: map, icon:mc});

다른 팁

I might be a bit late but I'll post a solution for others who have faced/are facing a similar issue. So basically what you have to do (at least for the solution you are seeking, i.e a custom image imposed on a box-like background) is impose the customImage on the background box with the help of a canvas. Using this implementation you can effectively create a BitmapDrawable from the canvas that you can then assign as a marker for your 'Overlay' / 'ItemizedOverlay'. Also, please refrain from creating an ImageView for each overlay as this will utterly destroy your memory/ your app if you have to deal with thousands of such ImageViews simultaneously. Instead, use BitmapDrawables that can be assigned to the overlays during their construction and don't consume nearly enough memory as an ImageView.

public BitmapDrawable imageOnDrawable(int drawableBackground, Bitmap customImage)
{
//The following line is optional but I'd advise you to minimize the size of 
//the size of the bitmap (using a thumbnail) in order to improve draw
//performance of the overlays (especially if you are creating a lot of overlays).

Bitmap customImageThumbnail = ThumbnailUtils.extractThumbnail(
                                                customImage, 100, 100); 

Bitmap bm = BitmapFactory.decodeResource(getResources(), drawableId);
bm = Bitmap.createScaledBitmap(bm, 112, 120, false);

Canvas canvas = new Canvas(bm);
canvas.drawBitmap(bm, 0, 0, null);
// The 6,6 in the below line refer to the offset of the customImage/Thumbnail
// from the top-left corner of the background box (or whatever you want to use
// as your background) 
canvas.drawBitmap(customImageThumbnail, 6, 6, null); 

return new BitmapDrawable(bm);

}

custom marker for Google Maps using a layout

View markerView = ((LayoutInflater) getActivity()
                        .getSystemService(
                                getActivity().LAYOUT_INFLATER_SERVICE))
                        .inflate(R.layout.map_marker, null);

set marker

 marker = map.addMarker(new MarkerOptions()
                                        .position(latLng)
                                        .title(strName)
                                        .snippet(strStatus)
                                        .icon(BitmapDescriptorFactory
                                                .fromBitmap(createDrawableFromView(
                                                        getActivity(),
                                                        markerView))));

Create Bitmap from Drawable

public static Bitmap createDrawableFromView(Context context, View view) {
    DisplayMetrics displayMetrics = new DisplayMetrics();
    ((Activity) context).getWindowManager().getDefaultDisplay()
            .getMetrics(displayMetrics);
    view.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT));
    view.measure(displayMetrics.widthPixels, displayMetrics.heightPixels);
    view.layout(0, 0, displayMetrics.widthPixels,
            displayMetrics.heightPixels);
    view.buildDrawingCache();
    Bitmap bitmap = Bitmap.createBitmap(view.getMeasuredWidth(),
            view.getMeasuredHeight(), Bitmap.Config.ARGB_8888);

    Canvas canvas = new Canvas(bitmap);
    view.draw(canvas);

    return bitmap;
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top