我在使用google mapV2,我从google place api下载图片,并希望在弹出窗口显示。[英] I my using google mapV2 and i m downloading image from google place api and want to display in the popup

本文是小编为大家收集整理的关于我在使用google mapV2,我从google place api下载图片,并希望在弹出窗口显示。的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

i m使用所有类通过URL获取图像的所有类.

        ImageView imV=  ((ImageView) view.findViewById(R.id.badge));
        // Image url
        String image_url = "http://maps.gstatic.com/mapfiles/place_api/icons/cafe-71.png";
        final int stub_id = R.drawable.ic_action_search;
        // ImageLoader class instance
        ImageLoader imgLoader = new ImageLoader(getApplicationContext());

        // whenever you want to load an image from url
        // call DisplayImage function
        // url - image url to load
        // loader - loader image, will be displayed before getting image
        // image - ImageView
        imgLoader.DisplayImage(image_url,stub_id ,imV);

但是它显示默认图像,而不是下载URL图像.

https://https://https://developers.google.com/maps/documentation/android/reference/com/google/android/gms/maps/googlemap.infowindowadapter

i m使用Goolge的InfowWindowAdapter类,它说我在窗口中加载数据和图像时不会更改图像,这就是为什么它显示首先显示默认图像.....且以后不更改

那么还有其他方法吗? 预先感谢

推荐答案

我遇到了同样的问题. 我已经用异步箱解决了.

像这样的东西

private Drawable _infoImageDrawable;
public class MyMapActivity extends MenuActivity
{
    .....code code code....

    protected void handleMarkerClicked(final Marker marker, final String url) {
        new AsyncTask<Void, Void, Void>()
        {   
            @Override
            protected void onPreExecute() 
            {
                super.onPreExecute();
                _infoImageDrawable = null;
            }

            @Override
            protected Void doInBackground(Void... params) 
            {
                InputStream is;
                try {
                     is = (InputStream) new URL(url).getContent();
                     _infoImageDrawable = Drawable.createFromStream(is, "");
                } catch (MalformedURLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                }
                return null;                
            }

            @Override
            protected void onPostExecute(Void result) 
            {
            super.onPostExecute(result);
            marker.showInfoWindow();
            }
        }.execute();
    }
}

然后,我只是将绘制的Infowdowadapter中的绘制设置为NULL(删除旧图像),然后将其设置为_imageInfodRawable的第二. 它有效 - 但我想要一个更好的解决方案.

本文地址:https://www.itbaoku.cn/post/102605.html

问题描述

i m using all the classes for geting image through Url.

        ImageView imV=  ((ImageView) view.findViewById(R.id.badge));
        // Image url
        String image_url = "http://maps.gstatic.com/mapfiles/place_api/icons/cafe-71.png";
        final int stub_id = R.drawable.ic_action_search;
        // ImageLoader class instance
        ImageLoader imgLoader = new ImageLoader(getApplicationContext());

        // whenever you want to load an image from url
        // call DisplayImage function
        // url - image url to load
        // loader - loader image, will be displayed before getting image
        // image - ImageView
        imgLoader.DisplayImage(image_url,stub_id ,imV);

but it is displaying the default image,rather than Url downloaded image.

https://developers.google.com/maps/documentation/android/reference/com/google/android/gms/maps/GoogleMap.InfoWindowAdapter

i m using infowindowAdapter class of goolge and its says that i cn't change the image when once data & image is loaded in the window,thts why its displaying first default image..... and not changing later

so is there any other way? thanks in advance

推荐答案

I'm having the same problem. I've solved it with a asyncTask.

Something like this

private Drawable _infoImageDrawable;
public class MyMapActivity extends MenuActivity
{
    .....code code code....

    protected void handleMarkerClicked(final Marker marker, final String url) {
        new AsyncTask<Void, Void, Void>()
        {   
            @Override
            protected void onPreExecute() 
            {
                super.onPreExecute();
                _infoImageDrawable = null;
            }

            @Override
            protected Void doInBackground(Void... params) 
            {
                InputStream is;
                try {
                     is = (InputStream) new URL(url).getContent();
                     _infoImageDrawable = Drawable.createFromStream(is, "");
                } catch (MalformedURLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                }
                return null;                
            }

            @Override
            protected void onPostExecute(Void result) 
            {
            super.onPostExecute(result);
            marker.showInfoWindow();
            }
        }.execute();
    }
}

Then I just set the drawable in the InfoWindowAdapter to null first(remove old image) and to _imageInfoDrawable second. It works - but i would like a better solution.