添加对自定义标记在谷歌地图API V2 [英] add cutom marker in google maps api v2

查看:172
本文介绍了添加对自定义标记在谷歌地图API V2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经实现在谷歌地图一个longclick监听器。所以当用户长点击地图上启动相机的意图,然后你可以拍照。现在我想达到什么是时拍摄图像获得放置在点地图的用户点击长上。

I have implemented a longclick listener in google maps. so when the user long click on the map it starts the camera intent and then you can take a picture. Now what i want to achieve is when that image is taken to get placed on the point on the map the users long clicked on.

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的)cuase,因为它涉及了一遍自败。 (我曾经尝试PRINTSCREEN,但速度还不够快:-))

So basically now the app crashes, the weird thing is that i can't seem to check the error message (logcat) cuase as soon as it comes up it dissapears again. (i have tried printscreen, but not fast enough :-) )

任何人都可以请提供一些线索这光,我能做些什么来解决这个问题?

Could anyone please shed some light on this and what i can do to resolve this?

感谢

推荐答案

这看起来错了我:

startActivityForResult(intent,TAKE_PICTURE);
googleMap.addMarker(new MarkerOptions().position(point)
        .icon(BitmapDescriptorFactory.fromResource(TAKE_PICTURE)));

第一条语句使用 TAKE_PICTURE 作为请求code代表开始活动。这可能是对的。第二条语句使用 TAKE_PICTURE 作为资源识别器(的东西在你的'资源'文件夹)。最有可能的第二个语句抛出一个异常,因为有该识别器没有资源,或者它是一个错误的类型BitmapDesc​​riptorFactory的。

The first statement uses TAKE_PICTURE as a request code for started Activity. This is probably right. The second statement uses TAKE_PICTURE as a resource identificator (to something in your 'res' folder). Most likely the second statement throws an exception because there's no resource for that identificator, or it is of a wrong type for BitmapDescriptorFactory.

当你调用 startActivityForResult 然后相机应用开始,而用户进行拍摄(或BACK按钮取消摄像头的应用程序),它需要一定的时间。你不能立即访问捕获的照片,你需要做的,在的onActivityResult 的处理程序,即:

When you call startActivityForResult then camera app starts, and it will take some time while user makes a shot (or cancels camera app by BACK button). You can't access captured photo immediately, you need to do that in onActivityResult handler, ie:

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
    }
}

由于图像是大的标记,你应该把它重新取样,以更小的东西。这是另一个问题,谷歌吧))

Since the image will be large for a marker, you should resample it to something smaller. It is other question, google for it ))

图片文件将在应用程序(SD卡)的外部存储被保存,如果它被安装。否则,该文件将被放置到应用程序的缓存目录在内部memmory。

The image file will be saved in external storage of the app (on SD card), if it is mounted. Otherwise it the file will be placed to application's cache dir in internal memmory.

这篇关于添加对自定义标记在谷歌地图API V2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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