下面就是我如何添加标记地图
Here is how i am adding marker to map
map.addMarker(new MarkerOptions()
.position(model.getLatLongfromService())
.title(model.getCoupon_name())
.snippet(model.getCoupon_id())
.icon(BitmapDescriptorFactory.fromFile(DataHolder.imageUrl
+ model.getCoupon_image())));
我越来越coupon_image格式如下: https://p.xsw88.cn/allimgs/daicuo/20230907/4536.png.JPG **
我收到此错误当u运行我的应用程序。
I am getting this error when u run my app.
java.lang.IllegalArgumentException异常:文件 http://test.xyz由Matchi.com提供回到/上传/ company_logo /采样徽标110x60.jpg 包含路径分隔符
java.lang.IllegalArgumentException: File https://p.xsw88.cn/allimgs/daicuo/20230907/4537.png.jpg contains a path separator
谁能帮我了解的问题是什么?
Can anyone help me to understand what the problem is ?
谢谢,拉克什
Thanks, Rakesh
推荐答案
我认为这个问题是该方法BitmapDescriptorFactory.fromFile使用参数字符串的文件名,从而重新presents的文件名(图像)加载。您提供的图像的HTTP URL( https://p.xsw88.cn/allimgs/daicuo/20230907/4538.png.jpg )代替它。
I think the problem is that method BitmapDescriptorFactory.fromFile uses parameter String fileName, which represents name of the file(image) to load. You supply image's http url (https://p.xsw88.cn/allimgs/daicuo/20230907/4537.png.jpg) instead of it.
您可能需要先下载图像,然后使用BitmapDescriptorFactory.fromBitmap;
You probably need to download the image first and then use BitmapDescriptorFactory.fromBitmap;
编辑:要下载图片,你可以使用一些AsyncTask的像这样的例子:
To download image, you can use some AsyncTask like this for example:
AsyncTask<String, Void, Bitmap> loadImageTask = new AsyncTask<String, Void, Bitmap>(){
@Override
protected Bitmap doInBackground(String... params) {
Bitmap bmImg = null;
try {
URL url = new URL(params[0]);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoInput(true);
conn.connect();
InputStream is = conn.getInputStream();
bmImg = BitmapFactory.decodeStream(is);
}
catch (IOException e)
{
e.printStackTrace();
bmImg = null;
}
return bmImg;
}
@Override
protected void onPostExecute(Bitmap result) {
super.onPostExecute(result);
// TODO: do what you need with resulting bitmap - add marker to map
}
};
这时别忘了适当的参数来执行的AsyncTask - 包含图像的URL字符串数组下载:
then don't forget to execute asynctask with proper parameter - String array containing url of image to download:
loadImageTask.execute(new String[]{yourImageUrl});
相关推荐
最新文章