无法将图标添加到标记,地图Android版V2 [英] Unable to add icon to Marker , Map V2 Android

查看:179
本文介绍了无法将图标添加到标记,地图Android版V2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面就是我如何添加标记地图

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格式如下: http://www.xyz.com/coupon21 .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 http://test.xyz.de/uploads/company_logo/sample-logo-110x60.jpg contains a path separator

    谁能帮我了解的问题是什么?

    Can anyone help me to understand what the problem is ?

    谢谢,
    拉克什

    Thanks, Rakesh

    推荐答案

    我认为这个问题是该方法BitmapDesc​​riptorFactory.fromFile使用参数字符串的文件名,从而重新presents的文件名(图像)加载。
    您提供的图像的HTTP URL( http://test.xyz.de/uploads /company_logo/sample-logo-110x60.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 (http://test.xyz.de/uploads/company_logo/sample-logo-110x60.jpg) instead of it.

    您可能需要先下载图像,然后使用BitmapDesc​​riptorFactory.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});
    

    这篇关于无法将图标添加到标记,地图Android版V2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆