解决方法:将PoiOverlay类中的getOverlayOptions()改成如下,且增加getResId方法
@Override
public final List<OverlayOptions> getOverlayOptions() {
if (mPoiResult == null || mPoiResult.getAllPoi() == null) {
return null;
}
List<OverlayOptions> markerList = new ArrayList<>();
int markerSize = 0;
for (int i = 0; i < mPoiResult.getAllPoi().size() && markerSize < MAX_POI_SIZE; i++) {
if (mPoiResult.getAllPoi().get(i).location == null) {
continue;
}
markerSize++;
Bundle bundle = new Bundle();
bundle.putInt("index", i);
int icon=getResId("icon_mark" + markerSize, R.drawable.class);
markerList.add(new MarkerOptions()
.icon(BitmapDescriptorFactory.fromResource(icon))
.extraInfo(bundle)
.position(mPoiResult.getAllPoi().get(i).location));
}
return markerList;
}
private static int getResId(String variableName, Class<?> c) {
try {
Field idField = c.getDeclaredField(variableName);
return idField.getInt(idField);
} catch (Exception e) {
e.printStackTrace();
return -1;
}
}
上述代码中的icon_mark图标请参考一下链接:
icon_mark图标传送门