我不明白为什么我没有在我的标记上获得更新图像?
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);
私有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;
}
请帮帮我。谢谢。
答案 0 :(得分:0)
您的代码是正确的,但我注意到用于加载图片的图片网址不正确,请在浏览器中打开该图片网址,它说网页不可用,所以舞会不在您的代码中,我认为问题出在Image url中,只需检查或更改它以进行测试。
答案 1 :(得分:0)
我没有看到任何通过http获取图像的代码。您需要添加用于建立http连接的代码,然后通过Internet使用InputStream检索图像。可能你错过了这件作品。
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);
如需进一步参考,请查看此SO答案。
How to create a custom-shaped bitmap marker with Android map API v2