0

我有一个函数可以在for循环中从解析服务器获取位置及其图像,然后将它们添加为谷歌地图上的标记,作为标记图标的缩略图工作得很好问题是当我点击任何标记时它显示最后一个发送的图像putExtra()

有没有办法让它显示正确的图像或其他方法而不是发送它以弹出样式putExtra()显示它。

以下是活动地图中的代码:

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;                                   }  });  }  });   }  }  });  }
4

1 回答 1

0

尝试:

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;                                   }  });
            }  });  }
于 2017-11-28T23:47:42.033 回答