【发布时间】:2014-11-28 06:29:58
【问题描述】:
我的地图上有 onMapClick,用户在该点拍照,然后将该图像作为缩略图返回到用户点击的那个点。但问题是,如果我指定 OnMapClick 和 onActivityResult 工作的位置。示例:
private LatLng point = new LatLng(xx.xxxx, xx.xxxx);
但如果我使用'onMapClick (LatLng point)' 中的点,然后将其添加到此:
public void onActivityResult(int requestCode, int resultCode, Intent data, **LatLng point**) {
然后在我的 onActivityResult 标记中使用它:
MarkerOptions markerOptions = new MarkerOptions()
.position(point)
.icon(BitmapDescriptorFactory
.fromBitmap(bitmap));
googleMap.addMarker(markerOptions);
然后一切仍然有效,但在点击的那一点上,图像没有显示在地图上。另外,日志中没有任何内容。所以我真的很困惑!
这是我的相机意图和 onActivityResult:
public void onMapClick(LatLng point) {
root = Environment.getExternalStorageDirectory().toString()
+ "/Your_Folder";
imageFolderPath = root + "/saved_images";
File imagesFolder = new File(imageFolderPath);
imagesFolder.mkdirs();
imageName = "test.png";
File image = new File(imageFolderPath, imageName);
fileUri = Uri.fromFile(image);
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
startActivityForResult(takePictureIntent,
TAKE_PICTURE);
}
public void onActivityResult(int requestCode, int resultCode, Intent data, LatLng point) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == TAKE_PICTURE && resultCode == RESULT_OK) {
Bitmap bitmap = null;
try {
GetImageThumbnail getImageThumbnail = new GetImageThumbnail();
bitmap = getImageThumbnail.getThumbnail(fileUri, this);
} catch (FileNotFoundException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}
MarkerOptions markerOptions = new MarkerOptions()
.position(point)
.icon(BitmapDescriptorFactory
.fromBitmap(bitmap));
googleMap.addMarker(markerOptions);
}
}
public void showFullImage(View view) {
String path = (String) view.getTag();
if (path != null) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
Uri imgUri = Uri.parse("file://" + path);
intent.setDataAndType(imgUri, "image/*");
startActivity(intent);
}
}
}
对不起,如果代码看起来很乱,但过去 4 天一直在解决这个问题,并且一直在添加、删除代码,当我得到这个工作时会整理 :-)
编辑
我认为正在发生的事情是,当您在地图上指向OnMapClickListener 时,OnActivityResult“忘记了(如果您愿意的话)”放置图像的位置。因此不给出任何错误消息并丢弃图像?
【问题讨论】:
标签: android google-maps