使用滑动图像库无法正常工作,在谷歌地图中加载包含图像的自定义标记

时间:2018-04-20 07:45:25

标签: android google-maps android-layout

我正在尝试使用滑动库加载多个带图像的自定义标记。 目前它只显示最后一个标记。但是,我想显示多个标记。我该如何解决这个问题?

用于显示标记的lat,long和image(图像url)来自服务器。

以下是我的代码:

 private void getZoom(List<Member> memberdata) {
        try {
            mMap.clear();
            for (int i = 0; i < memberdata.size(); i++) {

                Member members = memberdata.get(i);
                name = members.getMemberName();
                double latittude = Double.valueOf(members.getLat());
                double longitude = Double.valueOf(members.getLong());
                loc = new LatLng(latittude, longitude);
                String ImageUrl=members.getImageUrl();
                Glide.with(getApplicationContext())
                        .load(ImageUrl)
                        .asBitmap()
                        .fitCenter()
                        .diskCacheStrategy(DiskCacheStrategy.NONE)
                        .skipMemoryCache(true)
                        .transform(new CircleTransform(Main2Activity.this))
                        .into(new SimpleTarget<Bitmap>() {
                            @Override
                            public void onResourceReady(Bitmap bitmap, GlideAnimation<? super Bitmap> glideAnimation) {
                                Marker startPerc=mMap.addMarker(new MarkerOptions()
                                        .position(loc)
                                        .icon(BitmapDescriptorFactory.fromBitmap(getMarkerBitmapFromView(mCustomMarkerView, bitmap))));
                                mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(loc, 13f));
                              markers.add(startPerc);
                            }
                            @Override
                            public void onLoadFailed(Exception e, Drawable errorDrawable) {
                                Toast.makeText(Main2Activity.this,String.valueOf(e),Toast.LENGTH_SHORT).show();
                                System.out.println("exception"+e);
                                mMap.addMarker(new MarkerOptions()
                                        .icon(BitmapDescriptorFactory.fromResource(R.drawable.pin))
                                        .position(loc));
                            }
                        });

            }
            LatLngBounds.Builder builder = new LatLngBounds.Builder();
            for (Marker marker : markers) {
                builder.include(marker.getPosition());
            }
            LatLngBounds bounds = builder.build();

            int padding = (int) (80 * getResources().getDisplayMetrics().density);
            CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, padding);
            mMap.moveCamera(cu);
            mMap.animateCamera(cu);
        } catch (Exception e) {

        }
    }

服务器响应:

{
  "groupName": "Friends",
  "members": [
    {

      "imageUrl": "http://xxxxxxxx/get-profile-picture",
      "lat": 8.560408,
      "long": 76.880284
    },
    {

      "imageUrl": "http://xxxx/3031957896_bc7ef6918c.jpg",
      "lat": 8.558097,
      "long": 76.88156
    },
    {
      "imageUrl": "http://xxxxxx/PassPort-Size-Photograph-768x954.jpg",
      "lat": 8.5604818,
      "long": 76.8802502
    }
  ]
}

0 个答案:

没有答案