为什么自定义InfoWindow的谷歌地图v2,没有加载网址图片?

时间:2013-05-21 05:06:45

标签: android map

enter image description here我正在使用谷歌地图v2开发应用程序,在应用程序中,有自定义信息窗口,它没有从URL加载图像(由图像加载程序加载)请参阅附图以获得更多许可。           我的代码在这里 -

public class CustomWindowAdapter implements InfoWindowAdapter {
private Activity objactivity;
private List<GroupDealModle> mapList;

public CustomWindowAdapter(Activity objactivity,
        List<GroupDealModle> mapList) {
    this.objactivity = objactivity;
    this.mapList = mapList;
}

@Override
public View getInfoContents(Marker objmarker) {
    return null;
}

@Override
public View getInfoWindow(Marker objmarker) {
    View objview  = render(objmarker);
    return objview;
}

private View  render(Marker objmarker) {
    ImageLoader objloader = new ImageLoader(objactivity);
    View view = null;
    if (!objmarker.getTitle().equals("")) {
        int pos = Integer.parseInt(objmarker.getTitle());
        Log.e("==check position==", "" + pos);
        if (mapList != null && mapList.size() > pos) {
            String countvalue = mapList.get(pos).getCount();
            Log.e("==check count==", "" + countvalue);
            if (countvalue.equalsIgnoreCase("1")) {
                LayoutInflater inflater = (LayoutInflater) objactivity
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                view = inflater.inflate(R.layout.balloon_overlay, null, false);
                TextView objbusname = (TextView) view
                        .findViewById(R.id.balloon_item_title);
                TextView objballoon_item_desc = (TextView) view
                        .findViewById(R.id.balloon_item_desc);
                TextView objtitle = (TextView) view
                        .findViewById(R.id.balloon_item_snippet);
                ImageView objimgview = (ImageView) view
                        .findViewById(R.id.userthumb_inbaloon);
                TextView objtextexpired = (TextView) view
                        .findViewById(R.id.textexpired);

                objbusname.setText(mapList.get(pos).getBussiness_name());
                String expirevalue = mapList.get(pos).getExpire_status();
                if (expirevalue != null && expirevalue.equals("1")) {
                    objtextexpired.setVisibility(View.VISIBLE);
                }
                if (expirevalue != null && expirevalue.equals("0")) {
                    objtextexpired.setVisibility(View.GONE);
                }

                objtitle.setText(mapList.get(pos).getDeal_title());
                objballoon_item_desc.setText(mapList.get(pos)
                        .getDescription());
                String imageurl = mapList.get(pos).getImage();
                objloader.DisplayBanner(AppConstants.BASE_URL + imageurl,
                        objimgview, 65, 65);
            } else {
                LayoutInflater inflater = (LayoutInflater) objactivity
                        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                view = inflater.inflate(R.layout.transparentview, null, false);
                view.setVisibility(View.GONE);
                String userid = mapList.get(pos).getUser_id();
                LatLng objlatlng = objmarker.getPosition();
                double latitude = objlatlng.latitude;
                double longitude = objlatlng.longitude;
                Bundle objbundle = new Bundle();
                Intent objintent = new Intent(objactivity,
                        com.flashdeal.map.MapGroupData.class);
                objbundle.putString("from", "map");
                objbundle.putString("lat", "" + latitude);
                objbundle.putString("longi", "" + longitude);
                objbundle.putString("userid", "" + userid);
                objintent.putExtras(objbundle);
                objactivity.startActivity(objintent);
            }
        }
    }
    return view;

}

}

从服务器下载数据之后的这个适配器调用 -

@Override
    protected void onPostExecute(List<GroupDealModle> result) {
        if (objprogress.isShowing()) {
            objprogress.dismiss();
        }
        if (result != null) {
            mapList = result;
            myMap.setInfoWindowAdapter(new CustomWindowAdapter(MainActivity.this,mapList));

            if (result.size() != 0) {
                if (result != null) {
                    addPins(result);
                }
            } else if (frommovecurrent != null
                    && frommovecurrent.equalsIgnoreCase("yes")) {
                frommovecurrent = "no";
                addSingleMarker();
                addPins(result);

                /*
                 * // objLayout . removeAllViews (); // objLayout .addView(
                 * objviewformap ); objMapViewhelper . clearMap( );
                 * AlertDialog .Builder objbuilder = new AlertDialog
                 * .Builder( MainActivity .this); objbuilder . setMessage (
                 * "No deals found" ); objbuilder . setPositiveButton ("ok",
                 * new DialogInterface . OnClickListener () {
                 * 
                 * @Override public void onClick( DialogInterface arg0, int
                 * arg1) { } }); objbuilder . create(); objbuilder .show();
                 */
            } else if (result.size() == 0) {
                addSingleMarker();
                addPins(result);
            }
        }

    }

我已经看过这个stackoverflow讨论

Android Google maps APIv2 InfoWindow and Markers

但无法解决我的问题请任何人指导我。

3 个答案:

答案 0 :(得分:2)

Maps V2 UI实际上是由另一个进程呈现的。将View传递给Maps V2后,您无法修改用于信息窗口的View。我的猜测是你试图设置View然后以后加载图像,这是行不通的。首先获取图片,然后在将View提供给Maps V2之前将其放入View

当然,这与您链接的答案有关。

答案 1 :(得分:1)

Google已经更新了他的MAP(Android)功能,提高了性能等。 他将GeoPoint替换为LatLng(位置纬度的数据类型)。 MAP v1和v2之间的开发人员也有一些变化

如何在InfoWindow中加载动态图像

创建InfoWindow视图后,Google无法访问以修改或更改此视图。但你可以试试这个

static HashMap<String,String> loadImagesFlag = new HashMap<String, String>();

*/*create a AsyncTask for load image asynchronously */*

public class FetchImageTask extends AsyncTask<String, Integer, Bitmap> 
{

        @Override
        protected Bitmap doInBackground(String... arg0) {
            Bitmap b = null;
            try {
                Thread.sleep(500);
                b = BitmapFactory.decodeStream((InputStream) new URL(arg0[0]).getContent());
            } catch (MalformedURLException e) {
                //e.printStackTrace();
            } catch (IOException e) {
                //e.printStackTrace();
            }catch (Exception e){
                e.printStackTrace();
            }
            return b;
        }
}

public View getInfoWindow(final Marker marker){

      View view = getLayoutInflater().inflate(R.layout.custome_infowindow, null);
      ImageView driverImage = (ImageView) view.findViewById(R.id.img_driverphoto);
     /* Check this image is already load or not */
     if (DriverImageDTO.isLoadImage(driverName)) {
          /*set Image which is already loaded */
          driverImage.setImageBitmap(DriverImageDTO.DImage);
     }
     else if (!loadImagesFlag.containsKey(driverName)){
        final String vName = driverName;
        /* create HashMap to check status of Image is Load or not */
         loadImagesFlag.put(driverName,"true");
         new com.intelisky.FetchImageTask() {
             protected void onPostExecute(Bitmap result) {
                 if (result != null) {
                    try {
                        if(DriverImageDTO.driverimagelist==null){
                            DriverImageDTO.driverimagelist = new ArrayList<DriverImageDTO>();
                                        }
                            DriverImageDTO.driverimagelist.add(new DriverImageDTO(driverName, result));
                                        marker.setVisible(true);
                                        marker.hideInfoWindow();
                                        getInfoWindow(marker);
                                        marker.showInfoWindow();
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                    }
                                }
                            }
                        }.execute(imageurl));
                    }

     return view
}

答案 2 :(得分:0)

设置
时  myMap.setInfoWindowAdapter(new CustomWindowAdapter(MainActivity.this,mapList));

只需在CustomInfoWindowAdapter

中创建一个构造函数

私人标记mymarker;

 private class CustomInfoWindowAdapter implements InfoWindowAdapter {

            private View view;

            public CustomInfoWindowAdapter() {

                view = getActivity().getLayoutInflater().inflate(

                R.layout.group_custom_infowindow, null);
            }


    @Override
        public View getInfoContents(Marker marker) {

             if (mymarker != null
                    && mymarker
                            .isInfoWindowShown()) {

                mymarker.showInfoWindow();
            }


        return null;
    }


@Override
        public View getInfoWindow(final Marker marker) {

      mymarker = marker;


            String url = get url of image

            final ImageView image = ((ImageView) view.findViewById(R.id.badge));

            if (url != null && !url.equalsIgnoreCase("null")
                    && !url.equalsIgnoreCase("")) {
                imageLoader.displayImage(url, image, options,
                        new SimpleImageLoadingListener() {
                            @Override
                            public void onLoadingComplete(String imageUri,
                                    View view, Bitmap loadedImage) {
                                super.onLoadingComplete(imageUri, view,
                                        loadedImage);
                                getInfoContents(marker);
                            }
                        });
            } else {
                image.setImageResource(R.drawable.ic_stub);
            }


            return view;
        }

    }