0

Je voudrais insérer un extrait avec une image à l'intérieur, chaque fois que quelqu'un cliquera sur le marqueur, ils verront une image bitmap dans la description du marqueur (extrait).Comment mettre une image dans GoogleMaps api snippet

mSydney = mMap.addMarker(new MarkerOptions() 
      .position(SYDNEY) 
      .title("test") 
      .snippet(IMAGE HERE) 
      .icon(); 

J'ai une URL avec une image comment puis-je le faire?

+0

pouvez-vous ajouter une image par exemple comment cela devrait ressembler? – jagapathi

+0

@jagapathi juste une image à l'intérieur de l'extrait, comme ça: http://4.bp.blogspot.com/-pnpCR7AmHhQ/UPi07Uttk8I/AAAAAAAAG78/1Pl2txukbTs/s400/AndroidMapV2_InfoContents.png mais à l'intérieur de l'extrait et non dans le titre – drdisrespect

Répondre

1

I utilisé Picasso pour le chargement des images

Ceci est du code java pour gonfler la fenêtre d'information personnalisée

googleMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() { 
     @Override 
     public View getInfoWindow(final Marker marker) { 
      v[0] = getActivity().getLayoutInflater().inflate(R.layout.map_info_design, null); 
      if (marker != null) { 

       final ImageView logo=(ImageView)v[0].findViewById(R.id.logo); 




       t1=new Target() { 
        @Override 
        public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) { 
         logo.setImageBitmap(bitmap); 

        } 

        @Override 
        public void onBitmapFailed(Drawable errorDrawable) { 

        } 

        @Override 
        public void onPrepareLoad(Drawable placeHolderDrawable) { 

        } 
       }; 
       Picasso.with(getActivity()) 
         .load(b1.get(Integer.parseInt(marker.getSnippet()))).error(R.drawable.logo_icon) 
         .into(logo,new MarkerCallback(marker)); 

      } 
      return (v[0]); 
     } 

     @Override 
     public View getInfoContents(Marker marker) { 


      return null; 
     } 
    }); 

fichier XML de mise en page (R.layout.custom_marker_maps)

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="wrap_content" 
android:background="@drawable/comment_icon" 
android:padding="10dp" 
android:layout_height="wrap_content"> 

<ImageView 
    android:layout_width="60dp" 
    android:layout_marginLeft="10dp" 
    android:layout_marginStart="10dp" 
    android:layout_centerInParent="true" 
    android:layout_height="60dp" 
    android:id="@+id/logo"/> 

</RelativeLayout> 

Ajoutez ce code pour le rappel (pour résoudre bug Picasso)

static class MarkerCallback implements Callback { 
    Marker marker=null; 

    MarkerCallback(Marker marker) { 
     this.marker=marker; 
    } 

    @Override 
    public void onError() { 
     Log.e(getClass().getSimpleName(), "Error loading thumbnail!"); 
    } 

    @Override 
    public void onSuccess() { 
     if (marker != null && marker.isInfoWindowShown()) { 
      marker.hideInfoWindow(); 
      marker.showInfoWindow(); 
     } 
    } 
} 

SORTIE

enter image description here

+0

Merci, mais il semble que vous venez de changer l'icône du marqueur J'ai demandé à propos de la petite fenêtre (fenêtre d'informations) après avoir cliqué sur le marqueur, comment charger une image là-bas? – drdisrespect

+0

vous devez faire une fenêtre d'information personnalisée (modifier ma réponse) – jagapathi

+0

comment puis-je le faire? comment est-ce que je le fais apparaître quand vous appuyez sur un marqueur? – drdisrespect

0
fromAsset(String assetName) – Loading from assets folder 
fromBitmap (Bitmap image) – Loading bitmap image 
fromFile (String path) – Loading from file 
fromResource (int resourceId) – Loading from drawable resource 

// create marker 
MarkerOptions marker = new MarkerOptions().position(new LatLng(latitude, longitude)).title("Hello Maps"); 

// Changing marker icon 
marker.icon(BitmapDescriptorFactory.fromResource(R.drawable.my_marker_icon))); 

// adding marker 
googleMap.addMarker(marker); 
+0

this est comment changer l'icône du marqueur, j'ai demandé comment mettre une image de l'URL à l'extrait de marqueurs. – drdisrespect

+0

URL url = nouvelle URL ("http: // imageURL"); Bitmap bmp = BitmapFactory.decodeStream (url.openConnection(). GetInputStream()); googleMap.addMarqueur (bmp); – Siva

+0

mais je veux que le bmp soit à l'intérieur de l'extrait ..... – drdisrespect