2

Hi guys I have to put a customize image on everyMarker infowindow on my GoogleMap, on my Android application. But what I can not do is to fit the image with left, right and bottom border because, I think, the default Infowindow properties have a default padding or margin on the content.

Is it possible to fit the image with the Infowindow? Here my screenshot and my code:

Screenenter image description here

XML :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center_horizontal|left"
    android:orientation="horizontal">

    <ImageView
        android:id="@+id/image_nuvoletta"
        android:layout_width="90dp"
        android:layout_height="60dp"
        android:layout_marginRight="5dp"
        android:paddingLeft="0px"
        android:adjustViewBounds="true"
        android:src="@drawable/ic_launcher"/>
[...]

Java Snippet of getInfoContents

public View getInfoContents(Marker marker) {

/* Distanza a piedi e macchina sulla nuvoletta */
/***********************************************/
GPSTracker gpsTracker = new GPSTracker(MainActivity.this);

if (gpsTracker.canGetLocation())
{
    String stringLatitude = String.valueOf(gpsTracker.latitude);
    String stringLongitude = String.valueOf(gpsTracker.longitude);

    double currentLat = Double.parseDouble(stringLatitude);
    double currentLng = Double.parseDouble(stringLongitude);

    double destLat = marker.getPosition().latitude;
    double destLng = marker.getPosition().longitude;

    final float[] results = new float[3];
    Location.distanceBetween(currentLat, currentLng, destLat, destLng, results);

    float metri = results[0];
    float km = Math.round((double)metri/1000);

    int minuti_persona = (int)Math.round(metri/125);    //125 metri al minuto -> velocità media di 2,5 m/s
    int minuti_auto = (int)Math.round(km/0.7);          //700 metri al minuto -> velocità media di 42 km/h 


    /***********************************************/


    View v = getLayoutInflater().inflate(R.layout.custom_info_window, null);
    TextView tvTitle = (TextView) v.findViewById(R.id.title);
    TextView tvSnippet = (TextView) v.findViewById(R.id.snippet);
    tvSnippet.setTypeface(tvSnippet.getTypeface(), Typeface.ITALIC); //indirizzo in corsivo
    TextView tvPedonal_distance = (TextView) v.findViewById(R.id.pedonal_time);
    TextView tvCar_distance = (TextView) v.findViewById(R.id.car_time);
    tvTitle.setText(marker.getTitle());
    tvSnippet.setText(marker.getSnippet());

    if(minuti_persona <=0)          // Stampa tempo per coprire la distanza
    {
        tvCar_distance.setText("A piedi: meno di un minuto");
    }else
    {
        tvPedonal_distance.setText("A piedi: "+minuti_persona+ " minuti");
    }

    if(minuti_auto <= 0)
    {
        tvCar_distance.setText("In auto: meno di un minuto");                                   
    }else
    {
         tvCar_distance.setText("In auto: " +minuti_auto+ " minuti");
    }

    //Prova immagine custom
    /***********************************/
    ImageView image;
    String currentUrl="http://upload.wikimedia.org/wikipedia/commons/5/50/Casa_Natale_Benito_Mussolini_(1).jpg";
    image = (ImageView) v.findViewById(R.id.image_nuvoletta);

    Picasso.with(v.getContext())
        .load(currentUrl)
        .error(R.drawable.ic_launcher)  //in caso di errore fa vedere questa immagine (un triangolo penserei)
        .resize(150, 110)
        .into(image); 
    /***********************************/

    return v;
    }else
    {
        View v = getLayoutInflater().inflate(R.layout.custom_info_window, null);
        TextView tvTitle = (TextView) v.findViewById(R.id.title);
        TextView tvSnippet = (TextView) v.findViewById(R.id.snippet);
        tvTitle.setText(marker.getTitle());
        tvSnippet.setText(marker.getSnippet());
        return v;
    }

}

Thank you so much

Pierpaolo Ercoli
  • 1,028
  • 2
  • 11
  • 32

1 Answers1

0

instead of overwriting getInfoContents(Marker marker) just set a background to your xml custom layout and overwrite getInfoWindow(Marker marker).

A.sobhdel
  • 234
  • 4
  • 11