HashMap的不是onMarkerClick返回图像标记 [英] HashMap not returning image to marker by onMarkerClick

查看:146
本文介绍了HashMap的不是onMarkerClick返回图像标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有相机的意图创建,然后标记返回到地图为缩略图。现在我想要做的是挖掘上的标记为添加的每个标记上显示完整的图像。 previously我可以全屏显示图像,但它仅显示采取的所有标记,而不是每个标记各个图像最后一张图像。

I have a marker created by camera intent and then returned to the map as a thumbnail. Now what i want to do is to tap on the marker to display the full image for each marker that is added. Previously i can display the image in full screen, but it only displays the last image taken for all the markers and not the individual images for each marker.

下面是我的code:

Bitmap bitmap;
private String TAG;
File destinationFile;
public static final int CAPTURE_IMAGE_THUMBNAIL_ACTIVITY_REQUEST_CODE = 1888;
private Map<File, String> markerImagePathMap;


@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fragment_googlemaps);
        markerImagePathMap = new HashMap<File, String>();


  try {
        initilizeMap();

    } catch (Exception e) {
        e.printStackTrace();
    }
    }


private void initilizeMap() {
    if (googleMap == null) {
        googleMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();

        if (googleMap == null) {
            Toast.makeText(getApplicationContext(),
                    "Sorry! unable to create maps", Toast.LENGTH_SHORT)
                    .show();
        }
    }
}

@Override
    public void onResume() {
    super.onResume();
    initilizeMap();

    if (googleMap!=null){
      }

 CameraPosition cameraPosition = new CameraPosition.Builder().target(
         new LatLng(xx.xxxx, xx.xxxx)).zoom(9).bearing(0).tilt(80).build();

 googleMap.setOnMapClickListener(this);
 googleMap.setOnMapLongClickListener(this);
 googleMap.setOnMarkerClickListener(this);
 googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
 googleMap.setMapType(GoogleMap.MAP_TYPE_TERRAIN);
 googleMap.setMyLocationEnabled(true);
 googleMap.getUiSettings().setZoomControlsEnabled(false);
 googleMap.getUiSettings().setCompassEnabled(true);
 googleMap.getUiSettings().setMyLocationButtonEnabled(true);
}


public void onMapLongClick(final LatLng point) {

      googleMap.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {

          @Override
          public void onInfoWindowClick(Marker marker) {
              marker.remove();
            }
      });
      Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
      startActivityForResult(intent, CAPTURE_IMAGE_THUMBNAIL_ACTIVITY_REQUEST_CODE);
  }

protected void onActivityResult(int requestCode, int resultCode, Intent data)
{ 
    if (requestCode == CAPTURE_IMAGE_THUMBNAIL_ACTIVITY_REQUEST_CODE)
    {
        File imageStorageFolder = new File(Environment.getExternalStorageDirectory()+File.separator+"My Folder");
        if (!imageStorageFolder.exists())
        {
            imageStorageFolder.mkdirs();
            Log.d(TAG , "Folder created at: "+imageStorageFolder.toString());
        }
        if (data != null)
        {
            String filename = "image";
            String fileNameExtension = ".jpg";
            File sdCard = Environment.getExternalStorageDirectory();
            String imageStorageFolder1 = File.separator+"My Folder"+File.separator;
            destinationFile = new File(sdCard, imageStorageFolder1 + filename + fileNameExtension);
            Log.d(TAG, "the destination for image file is: " + destinationFile );
            if (data.getExtras() != null)
            {
                bitmap = (Bitmap)data.getExtras().get("data");
                try
                {
                    FileOutputStream out = new FileOutputStream(destinationFile);
                    bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
                    out.flush();
                    out.close();
                }
                catch (Exception e)
                {
                    Log.e(TAG, "ERROR:" + e.toString());
                }
                MarkerOptions markerOptions = new MarkerOptions()
                            .draggable(true)
                            .snippet("Snippet")
                            .title("Title")
                            .position(position)
                            .icon(BitmapDescriptorFactory
                                    .fromBitmap(bitmap));
                            googleMap.addMarker(markerOptions);
                            Marker marker = googleMap.addMarker(markerOptions);
                            markerImagePathMap.put(destinationFile, marker.getId());
            }
        }
    }
 }
        public void onMapClick (LatLng point){
    }
 {
 }
    @Override
        public boolean onMarkerClick (Marker marker){

        markerImagePathMap.put(destinationFile, marker.getId());         
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_VIEW);
            markerImagePathMap.put(destinationFile, marker.getId());
            Uri imgUri = Uri.parse("file://" + markerImagePathMap.get(marker.getId()));
            intent.setDataAndType(imgUri, "image/*");
            startActivity(intent);
          return false;
  }
 }

但问题是,在标记上敲击时没有显示任何图像,它只是显示此图像(找不到文件或破裂,或诸如此类的话)

But the problem is that it isn't displaying any image when tapping on the marker it just displays this image (file not found or broken or something to that effect)

推荐答案

如果你想要做的是这样的:

If you want to do like this:

Uri imgUri = Uri.parse("file://" + markerImagePathMap.get(marker.getId())

你需要做的是这样的:

you need to do like this:

markerImagePathMap.put(marker.getId(), destinationFile);

所以,code应该是这样的:

So the code should be like this:

private Map<String, File> markerImagePathMap;

protected void onCreate(Bundle savedInstanceState) {
    ...
    markerImagePathMap = new HashMap<String, File>();
    ...
}

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    ...
    //destinationFile = new File(sdCard, imageStorageFolder1 + filename + fileNameExtension);  // <--- Delete
    File destinationFile = new File(sdCard, imageStorageFolder1 + filename + fileNameExtension);  // <--- Add
    ...
    Marker marker = googleMap.addMarker(markerOptions);
    Log.d(TAG, marker.getId() + " -> " + destinationFile.getAbsolutePath());   // <--- Add
    markerImagePathMap.put(marker.getId(), destinationFile);
    ...
}

public boolean onMarkerClick (Marker marker){
    ...
    //markerImagePathMap.put(destinationFile, marker.getId());  <-- what is this for?
    File destinationFile = markerImagePathMap.get(marker.getId())
    Uri imgUri = Uri.parse("file://" + destinationFile.getAbsolutePath());
    ...
}

这篇关于HashMap的不是onMarkerClick返回图像标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆