Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
331 views
in Technique[技术] by (71.8m points)

android - I my using google mapV2 and i m downloading image from google place api and want to display in the popup

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...