OnMarkerClickListener 为所有标记显示相同的图像

OnMarkerClickListener shows the same image for all markers

我有一个函数可以在 for 循环中从解析服务器获取位置及其图像,然后将它们作为标记添加到 google 地图上,作为标记图标的缩略图工作得很好问题是什么时候我单击任何标记,它显示了用 putExtra().

发送的最后一张图像

有没有办法让它显示正确的图像或其他方法,而不是用 putExtra() 发送它以在 pop up style 中显示。

这是actvitymap中的代码:

public void getimagesLocation(){

        ParseQuery<ParseObject> query = ParseQuery.getQuery("Image");
        ParseGeoPoint geoPointLocation = new ParseGeoPoint();
        query.whereNear("location", geoPointLocation);
        query.setLimit(100);
        Log.i("imageslocation", "limit set to 100 image on map");
        query.findInBackground(new FindCallback<ParseObject>() {
            @Override
            public void done(List<ParseObject> objects, ParseException e) {
                if (e == null) {
                    Log.i("imageslocation", "no errors");
                }

                if (objects.size() > 0) {
                    for (ParseObject object : objects) {
                        //This is the loop function to get all images from parseserver
                        final ParseGeoPoint point = object.getParseGeoPoint("location");
                        ParseFile file = (ParseFile) object.get("image");
                        file.getDataInBackground(new GetDataCallback() {
                            @Override
                            public void done(byte[] data, ParseException e) {
                                if (e == null && data != null);
                                Bitmap bitmap = BitmapFactory.decodeByteArray(data,0,data.length);


                                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                                bitmap.compress(Bitmap.CompressFormat.JPEG, 50, baos);
                                final byte[] b = baos.toByteArray();


                                // thumbnail that will replace the marker icon
                                Bitmap thumbnail = ThumbnailUtils.extractThumbnail(getCroppedBitmap(bitmap),200,200);

                                Double lat = point.getLatitude();
                                Double lng = point.getLongitude();

                                LatLng marker = new LatLng(lat, lng);
                                Log.i("imageslocation", "Latitude :" + lat + " Longitude: " + lng);


                                mMap.addMarker(new MarkerOptions()
                                        .title("Another Image")
                                        .icon(BitmapDescriptorFactory.fromBitmap(thumbnail))
                                        //.infoWindowAnchor(0.5f, 0.5f)                                //.snippet("You can and will achieve")
                                        .position(marker));
                                mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
                                    @Override
                                        public boolean onMarkerClick (Marker marker){

                                        Intent intent = new Intent(MapScreen.this, FullimageScreen.class);
                                        intent.putExtra("picture", b);
                                        startActivity(intent);

                                        return true;                                   }  });  }  });   }  }  });  }

尝试:

public void getimagesLocation(){

    ParseQuery<ParseObject> query = ParseQuery.getQuery("Image");
    ParseGeoPoint geoPointLocation = new ParseGeoPoint();
    query.whereNear("location", geoPointLocation);
    query.setLimit(100);
    Log.i("imageslocation", "limit set to 100 image on map");
    query.findInBackground(new FindCallback<ParseObject>() {
        @Override
        public void done(List<ParseObject> objects, ParseException e) {
            if (e == null) {
                Log.i("imageslocation", "no errors");
            }

            if (objects.size() > 0) {
                for (ParseObject object : objects) {
                    //This is the loop function to get all images from parseserver
                    final ParseGeoPoint point = object.getParseGeoPoint("location");
                    ParseFile file = (ParseFile) object.get("image");
                    file.getDataInBackground(new GetDataCallback() {
                        @Override
                        public void done(byte[] data, ParseException e) {
                            if (e == null && data != null);
                            Bitmap bitmap = BitmapFactory.decodeByteArray(data,0,data.length);


                            ByteArrayOutputStream baos = new ByteArrayOutputStream();
                            bitmap.compress(Bitmap.CompressFormat.JPEG, 50, baos);
                            final byte[] b = baos.toByteArray();


                            // thumbnail that will replace the marker icon
                            Bitmap thumbnail = ThumbnailUtils.extractThumbnail(getCroppedBitmap(bitmap),200,200);

                            Double lat = point.getLatitude();
                            Double lng = point.getLongitude();

                            LatLng marker = new LatLng(lat, lng);
                            Log.i("imageslocation", "Latitude :" + lat + " Longitude: " + lng);


                            Marker newMarker = mMap.addMarker(new MarkerOptions()
                                    .title("Another Image")
                                    .icon(BitmapDescriptorFactory.fromBitmap(thumbnail))
                                    //.infoWindowAnchor(0.5f, 0.5f)                                //.snippet("You can and will achieve")
                                    .position(marker));
                            newMarker.setTag(b);
                              }  });   }
                mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
                    @Override
                        public boolean onMarkerClick (Marker marker){

                        Intent intent = new Intent(MapScreen.this, FullimageScreen.class);
                        intent.putExtra("picture", (byte[]) marker.getTag());
                        startActivity(intent);

                        return true;                                   }  });
            }  });  }