Skip to content

Commit 86f3627

Browse files
committed
fix: no InfoWindow when the title is null
1 parent 838b5d1 commit 86f3627

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

library/src/main/java/com/google/maps/android/data/Renderer.java

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,26 +1145,33 @@ private void setMarkerInfoWindow(KmlStyle style, Marker marker,
11451145

11461146
/**
11471147
* Creates a new InfoWindowAdapter and sets text if marker snippet or title is set. This allows
1148-
* the info window to have custom HTML.
1148+
* the info window to have custom HTML. If the marker has no title, the InfoWindow is deactivated.
11491149
*/
11501150
private void createInfoWindow() {
11511151
mMarkers.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {
11521152

1153-
public View getInfoWindow(@NonNull Marker arg0) {
1153+
public View getInfoWindow(@NonNull Marker marker) {
11541154
return null;
11551155
}
11561156

11571157
@Override
1158-
public View getInfoContents(@NonNull Marker arg0) {
1158+
public View getInfoContents(@NonNull Marker marker) {
1159+
if (marker.getTitle() == null) {
1160+
return null;
1161+
}
1162+
11591163
View view = LayoutInflater.from(mContext).inflate(R.layout.amu_info_window, null);
1160-
if (arg0.getTitle() != null) {
1161-
TextView infoWindowText = view.findViewById(R.id.window);
1162-
if (arg0.getSnippet() != null) {
1163-
infoWindowText.setText(Html.fromHtml(arg0.getTitle() + "<br>" + arg0.getSnippet()));
1164-
} else {
1165-
infoWindowText.setText(Html.fromHtml(arg0.getTitle()));
1166-
}
1164+
TextView infoWindowText = view.findViewById(R.id.window);
1165+
1166+
String title = marker.getTitle();
1167+
String snippet = marker.getSnippet();
1168+
1169+
if (snippet != null) {
1170+
infoWindowText.setText(Html.fromHtml(title + "<br>" + snippet));
1171+
} else {
1172+
infoWindowText.setText(Html.fromHtml(title));
11671173
}
1174+
11681175
return view;
11691176
}
11701177
});

0 commit comments

Comments
 (0)