У меня есть вид рециркулятора, в котором каждый элемент представляет собой cardView, и у него есть свои собственные облегченные карты Google, которые содержат два разных маркера.Я хочу переместить камеру таким образом, чтобы область маркеров вписывалась в некоторые отступы.
Я пытался сделать, как говорится в документации Google, но он просто не работает или работает по-разному с каждым элементом.
Я реализую всю логику карты в классе myViewHolder, может быть, это имеет какое-то влияние?
Я пробовал разные значения отступов, но ни одно из них не работает, поэтому 500 - это только последнееодин, который я попробовал.
public class myViewHolder extends RecyclerView.ViewHolder implements OnMapReadyCallback {
TextView orderDate;
TextView orderTime;
TextView orderStatus;
TextView itemsName;
TextView itemsCount;
ImageView expandOrder;
GoogleMap map;
View layout;
myViewHolder(View itemView) {
super(itemView);
layout = itemView;
orderDate = itemView.findViewById(R.id.txt_order_date);
orderTime = itemView.findViewById(R.id.txt_order_time);
orderStatus = itemView.findViewById(R.id.txt_order_status);
itemsName = itemView.findViewById(R.id.txt_itemsName);
itemsCount = itemView.findViewById(R.id.txt_itemsCount);
expandOrder = itemView.findViewById(R.id.imageExpandOrder);
// For map view
mapView = itemView.findViewById(R.id.lite_listrow_map);
if(mapView != null){
//Initialise the MapView
mapView.onCreate(null);
mapView.getMapAsync(this);
}
}
@Override
public void onMapReady(GoogleMap googleMap) {
MapsInitializer.initialize(context);
map = googleMap;
setMapLocation();
}
private void setMapLocation(){
if (map == null) return;
map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
OrderModel order = (OrderModel) mapView.getTag();
if(order == null) return;
// Sets markers to the map and sets the camera
LatLng pickUp = LocationParser.getLocationFromAddress(context,order.getPickUpAddress());
LatLng dropOf = LocationParser.getLocationFromAddress(context, order.getDropOfAddress());
map.addMarker(new MarkerOptions()
.position(pickUp)
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_CYAN)));
map.addMarker(new MarkerOptions()
.position(dropOf)
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_CYAN)));
showCurvedPolyline(pickUp,dropOf, 0.2);
LatLngBounds.Builder builder = new LatLngBounds.Builder();
builder.include(pickUp);
builder.include(dropOf);
LatLngBounds bounds = builder.build();
map.setPadding(0, 0, 0 ,150);
int padding = 500; // offset from edges of the map in pixels
map.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, padding));
}
Вот как это выглядит
Как вы можете видеть, у первого автомобиля вообще нет подкладки, а у второго довольно хороший, но второйони разные.