android - 在 Android 中的 recylerview 上实现地图时,Google Map 返回空对象引用
问题描述
我正在 recylerview 适配器上实现谷歌地图,但它返回空对象引用。
尝试在一个空对象引用
public class TripAdapterViewHolder extends RecyclerView.ViewHolder implements OnMapReadyCallback {
TripAdapterBinding tripAdapterBinding;
MapView mapView;
GoogleMap gMap;
TripAdapterViewHolder(TripAdapterBinding tripAdapterBinding) {
super(tripAdapterBinding.itemTrip);
this.tripAdapterBinding = tripAdapterBinding;
setMap(tripAdapterBinding.map);
}
public void setMap(MapView map) {
mapView = map;
if (mapView != null)
{
mapView.onCreate(null);
mapView.onResume();
mapView.getMapAsync(this);
}
}
@Override
public void onMapReady(GoogleMap googleMap) {
this.gMap = googleMap;
}
我打电话给我的持有人在地图上显示数据
@Override
public void onBindViewHolder(@NonNull TripAdapter.TripAdapterViewHolder holder, int position) {
try {
GoogleMap thisMap = holder.gMap;
LatLng startPoint = new LatLng(37.7750, 122.4183);
thisMap.addMarker(new MarkerOptions()
.position(startPoint)
.title("")
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN)));
thisMap.animateCamera(CameraUpdateFactory.newLatLngZoom(startPoint, 12));
}catch (Exception e){
Log.e("MapException "," "+e.getMessage());
}
holder.bindTrip(tripLists.get(position));
}
解决方案
您应该通过显示路径来使用静态地图。
静态地图图像生成 在这里您将获得地图图像,您可以使用它在回收站视图适配器中显示。
推荐阅读
- hadoop - 刷新 Hive 中的 Hive 表
- css - SVG CSS 颜色样式
- hibernate - Hibernate 不会在 hbm2ddl.auto="update" 上的表中添加新列
- rest - 在没有 Azure 的情况下使用自己的 API 创建 CRUD Powerapps?
- javascript - 关联结算帐户后,Google Maps JavaScript API 密钥不起作用
- python - 如何在 python 中安装 PostgreSQL 函数?
- html - 打开表单列表时自动选择第一个表单
- amazon-web-services - ObjectRemoved 事件持续触发的 Lambda 函数
- express - ES6 Router.use() 需要一个中间件函数但得到一个对象
- mongodb - docker-compose mongodb phoenix,[错误] 连接失败:**(Mongo.Error)tcp 连接:连接被拒绝 - :econnrefused