I have a map activity where I want to have customised info window for my markers. In that window I want to load a picture from a file, and add some additional text (which I will add later).
The problem is, when I have a picture file in landscape mode, the photo loads and shown in the marker's info window with the right dimensions. However, if the file is in portrait mode, the info window appears with the right dimension (indeed portrait), but there is no picture shown. I checked that the portrait image file exists, it has the correct file path, but I can't find out why portrait pictures do not show.
Here is my code:
// Initializing the custom info window as per info_window.xml
if (mMap != null) {
mMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {
@Override
public View getInfoWindow(Marker marker) {
return null;
}
@Override
public View getInfoContents(Marker marker) {
View view = getLayoutInflater().inflate(R.layout.info_window, null);
mImageView = view.findViewById(R.id.markerImageView);
for (Picture picture : mPictureList) {
if (picture.getMarker().equals(marker)) {
String path = picture.getPicturePath();
int width = 160;
int height = 90;
ExifInterface data = null;
try {
data = new ExifInterface(path);
String orientation = data.getAttribute(ExifInterface.TAG_ORIENTATION);
// 1 for landscape, 3 for landscape upside down
// 6 for portrait, 8 is portrait upside down
if (orientation.equalsIgnoreCase("6") || orientation.equalsIgnoreCase("8")) {
width = 90;
height = 160;
}
} catch (IOException e) {
e.printStackTrace();
}
// setting the new dimensions in dp
mImageView.getLayoutParams().height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, height, getResources().getDisplayMetrics());
mImageView.getLayoutParams().width = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, width, getResources().getDisplayMetrics());
mImageView.requestLayout();
Picasso.with(MapsActivity.this)
.load("file://" + path)
.resize(width, height)
.centerCrop()
.into(mImageView);
} else {
Log.d(TAG, "getInfoContents: Didn't find any picture with that marker");
}
}
return view;
}
});
}
And the info_window.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="@+id/markerImageView"
android:layout_width="160dp"
android:layout_height="160dp"/>
</LinearLayout>
I finally found a solution to this problem. I was using the latest version of picasso 2.3.2 which has an issue with displaying images (as per https://github.com/square/picasso/issues/530) I switched to version 2.2.0 and the problem got solved.
P.S. Version 2.4.0 should fix the problem described above.