我在谷歌地图中实现了一个longclick监听器。因此,当用户长时间点击地图时,它会启动相机意图然后您可以拍照。现在我想要实现的是当图像被放置在用户长时间点击的地图上的点上时。
googleMap.setOnMapLongClickListener(Test.this);
googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
// adding marker
googleMap.setMapType(GoogleMap.MAP_TYPE_TERRAIN);
googleMap.setMyLocationEnabled(true); // false to disable
googleMap.getUiSettings().setZoomControlsEnabled(false); // true to enable
googleMap.getUiSettings().setCompassEnabled(true);
googleMap.getUiSettings().setMyLocationButtonEnabled(true);
}
{
}
@Override
public void onMapLongClick(LatLng point) {
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
startActivityForResult(intent,TAKE_PICTURE);
googleMap.addMarker(new MarkerOptions().position(point)
.icon(BitmapDescriptorFactory.fromResource(TAKE_PICTURE)));
Toast.makeText(getApplicationContext(),
"New marker added@" + point.toString(), Toast.LENGTH_LONG)
.show();
}
}
所以基本上现在应用程序崩溃,奇怪的是我似乎无法一旦检查错误消息(logcat),就会再次消失。 (我已经尝试过printcreen,但速度不够快:-))
有谁能请说明这一点以及我能做些什么来解决这个问题?
由于
答案 0 :(得分:0)
这对我来说不合适:
startActivityForResult(intent,TAKE_PICTURE);
googleMap.addMarker(new MarkerOptions().position(point)
.icon(BitmapDescriptorFactory.fromResource(TAKE_PICTURE)));
第一个语句使用TAKE_PICTURE
作为已启动活动的请求代码。这可能是正确的。第二个语句使用TAKE_PICTURE
作为资源标识符(对于'res'文件夹中的某些内容)。很可能第二个语句抛出异常,因为该标识符没有资源,或者BitmapDescriptorFactory的类型错误。
当您拨打startActivityForResult
时,相机应用程序会启动,用户进行拍摄需要一些时间(或者通过“返回”按钮取消相机应用程序)。您无法立即访问捕获的照片,您需要在onActivityResult
处理程序中执行此操作,即:
private File photo = null;
/**
* This method is used to start the camera activity and save the image taken as the imagename passed
*
* @param imagename : this is the name of the image which will be saved
*/
private void clickPicture(String imagename) {
Intent getCameraImage = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); // this is the same as ""android.media.action.IMAGE_CAPTURE"
File cameraFolder;
if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED))
cameraFolder = new File(android.os.Environment.getExternalStorageDirectory(),"myfolder/");
else
cameraFolder= context.getCacheDir();
if(!cameraFolder.exists())
cameraFolder.mkdirs();
String imageFileName = imagename;
photo = new File(cameraFolder, "myfolder/" + imageFileName);
getCameraImage.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
Uri.fromFile(photo);
startActivityForResult(getCameraImage, TAKE_PICTURE);
}
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
if(resultCode == RESULT_OK) {
// read captured image from File photo and place it to map
}
}
由于标记的图像较大,因此应将其重新取样为较小的标记。这是另一个问题,google for it))
如果已安装,图像文件将保存在应用程序的外部存储器中(在SD卡上)。否则,文件将被放置在内部memmory中的应用程序缓存目录中。