Google地图不响应相机填充

时间:2019-06-06 14:35:27

标签: java android google-maps

我有回收站视图,其中每个项目都是cardView,并且它具有自己的精简版Google地图,其中包含两个不同的标记。我想移动相机,以使标记的划痕适合某些填充物。

我已经尝试过按照Google文档的说明进行操作,但是它只是行不通,或者与每个项目都不同。

我正在myViewHolder类中实现map的所有逻辑,也许会产生一些影响?

我尝试了不同的padding值,但是没有一个起作用,所以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));
        }

这就是它的样子 screenshot

如您所见,冷杉的车根本没有填充物,而第二辆车则是丘特好的,但它们却有所不同。

0 个答案:

没有答案