在onMapReady内,毕加索不会在第一次加载图像并且在重新创建活动后加载图像

时间:2019-05-04 13:40:19

标签: android firebase google-maps

在应用程序中使用了毕加索,它工作正常,除非我在onMapReady中使用它来加载标记图像,并且第一次无法使用。这是我的代码:

   @Override
public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;


    mMap.getUiSettings().setZoomControlsEnabled(true);
    mMap.getUiSettings().setMyLocationButtonEnabled(true);

    // Add a marker and move the camera
    mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(Double.parseDouble(sharedPreferences.getString("CurntLatitude","24.74")),Double.parseDouble(sharedPreferences.getString("CurntLongitude","46.61"))),14));
    get_seller_user();




} 

公共标记createMarker(整数布局,双纬度,双经度,字符串profile_img,布尔值交付服务,布尔事件服务,字符串ID){

    View marker = ((LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(layout, null);

     markerImage =  marker.findViewById(R.id.user_dp);
    ImageView online_status =  marker.findViewById(R.id.online_status);
    ImageView events =  marker.findViewById(R.id.for_group_img);
    ImageView delivery =  marker.findViewById(R.id.can_deliver_img);

    if(events_services){
    events.setVisibility(View.VISIBLE);}
    if(delivery_sevices){
    delivery.setVisibility(View.VISIBLE);}


    //picaso for loade image
    Picasso.with(getActivity()).load(profile_img).into(markerImage);





    DisplayMetrics displayMetrics = new DisplayMetrics();
    getActivity().getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);



    marker.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    marker.measure(displayMetrics.widthPixels, displayMetrics.heightPixels);
    marker.layout(0, 0, displayMetrics.widthPixels, displayMetrics.heightPixels);
    marker.buildDrawingCache();
    Bitmap bitmap = Bitmap.createBitmap(marker.getMeasuredWidth(), marker.getMeasuredHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    marker.draw(canvas);



    return mMap.addMarker(new MarkerOptions()
            .position(new LatLng(latitude,longitude)).icon(BitmapDescriptorFactory.fromBitmap(bitmap)).title(id));


}




public  void get_seller_user() {

    Query Query = database.orderByChild("acount_type").equalTo("seller");
    Query.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            Users users;
            for (DataSnapshot Snapshot: dataSnapshot.getChildren()) {
                 users = Snapshot.getValue(Users.class);
                 createMarker(R.layout.custom_marker,Double.parseDouble(users.getLatitude()),Double.parseDouble(users.getLongitude()),users.getProfile_img(),users.isDelivery_sevices(),users.isEvents_services(),users.getUser_id());
            }

        }
            @Override
        public void onCancelled(DatabaseError databaseError) {
            Log.e(TAG, "onCancelled", databaseError.toException());

        }

    });

}

0 个答案:

没有答案