1

I am not to understand why i am not getting update image on my marker?

String atvar_url = "uscalumni.gameday-data.com/upload/22081449748313.jpg";

            MarkerOptions options = new MarkerOptions();
            options.title("");
            options.position(latLng);
            options.icon(BitmapDescriptorFactory.fromBitmap(createDrawableFromView(atvar_url, true)));
            options.anchor(0.5f, 1);
            Marker m = googleMap.addMarker(options);
            markerPicMap.put(atvar_url,m);

private Bitmap createDrawableFromView(final String atvar_url, boolean isCallback) {

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

    View marker = ((LayoutInflater) getActivity().getSystemService(Activity.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.custom_marker_layout, null);
    final ImageView img = (ImageView) marker.findViewById(R.id.img_profile);


    Callback callback = null;
    if (isCallback) {
        callback = new Callback() {
            @Override
            public void onSuccess()
            {
                try {
                    if (markerPicMap != null && markerPicMap.containsKey(atvar_url)) {
                        Marker m = markerPicMap.get(atvar_url);
                        if (m != null) {
                            Bitmap bmp = createDrawableFromView(atvar_url, false);
                            Log.e("Sundeep", "Success" +  bmp);
                            m.setIcon(BitmapDescriptorFactory.fromBitmap(createDrawableFromView(atvar_url, false)));
                        }
                    }
                }catch (Exception e) {e.printStackTrace();}
            }

            @Override
            public void onError() {
                Log.e("Sundeep", "there is error");
            }
        };
    }
    Picasso.with(getActivity()).load(atvar_url).placeholder(R.drawable.default_user).into(img, callback);
    marker.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.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 bitmap;
}

Please help me.Thanks in advance.

Sundeep Badhotiya
  • 810
  • 2
  • 9
  • 14

2 Answers2

0

Your code is correct,But i have noticed that the image url for loading image is not correct,Please just open that image url in browser,it says the webpage is not available,So prom is not in your code,I think problem is in Image url,Just check it or change it for testing purpose.

JIGAR
  • 302
  • 2
  • 15
0

I do not see any code that is fetching the image over http. You need to add the code for making the http connection and then retrieving the image using InputStream over the internet. Probably you are missing that piece.

URL url = new URL(user_image_url);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();   
conn.setDoInput(true);   
conn.connect();     
InputStream is = conn.getInputStream();
bmImg = BitmapFactory.decodeStream(is); 

For further reference, take a look at this SO answer.

How to create a custom-shaped bitmap marker with Android map API v2

Community
  • 1
  • 1
AniV
  • 3,997
  • 1
  • 12
  • 17