2010-09-24 4 views
1

Je veux créer un marqueur MapView avec 4 éléments: - image (de l'utilisateur) - fond - texte (nom d'utilisateur) - flèche pour afficher une directioncomment créer un marqueur de cartes android personnalisé?

OverlayItem.setMarker() acceptent seulement drawable.

Comment est-ce que je peux créer un drawable avec 4 articles? Ou puis-je ajouter une vue en tant que marqueur à overlayItem?

des idées?

Répondre

1

J'ai trouvé une solution. créer un BitmapDrawable

Voici le code

 Bitmap photo = ((BitmapDrawable)mActivity.getResources().getDrawable(R.drawable.user_picture_dummy)).getBitmap(); 

     Bitmap returnedBitmap = Bitmap.createBitmap(Global.dipToPx(40), Global.dipToPx(67), Bitmap.Config.ARGB_8888); 
     Canvas canvas = new Canvas(returnedBitmap); 

     mBackground.setBounds(0, Global.dipToPx(10), canvas.getWidth(), canvas.getHeight()); 
     mBackground.draw(canvas); 

     m.postScale((float)Global.dipToPx(30)/(float)photo.getWidth(), (float)Global.dipToPx(30)/(float)photo.getHeight()); 
     m.postTranslate(Global.dipToPx(5), Global.dipToPx(15)); 
     canvas.drawBitmap(photo, m, paint); 
     m.reset(); 

     canvas.drawText(Global.DateToTimeString(adv.getStartDateMS()), Global.dipToPx(20), Global.dipToPx(10), paint); 

     mat.postRotate((float)bearingTo(adv.getDepGeoPoint(), adv.getArrLocationObj().getGeoPoint()), mDirection.getWidth()/2, mDirection.getHeight()/2); 
     mat.postTranslate(canvas.getWidth()-mDirection.getWidth(), canvas.getHeight()-mDirection.getHeight()-Global.dipToPx(12)); 
     canvas.drawBitmap(mDirection, mat, paint); 
     mat.reset(); 

     BitmapDrawable drawable = new BitmapDrawable(returnedBitmap); 
     boundCenter(drawable); 

     OverlayItem item = new OverlayItem(adv.getDepGeoPoint(), adv.getOwnerObj().getUserName(), adv.getOwnerObj().getUserName()); 
     item.setMarker(drawable); 
+2

Je pense que c'est ** ** inclomplete par exemple D'où vient le 'mat'? quel type a-t-il? – Jonas

Questions connexes