Я реализую карту Google на адаптере recylerview, но она возвращает нулевую ссылку на объект.
Попытка вызвать виртуальный метод 'com.google.android.gms.maps.model.Marker com.google.android.gms.maps.GoogleMap.addMarker (com.google.android.gms.maps.model .MarkerOptions) 'для ссылки на пустой объект
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));
}