【问题标题】:How to get latitude and longitude from captured image -- Android如何从捕获的图像中获取经纬度 -- Android
【发布时间】:2013-07-17 14:05:03
【问题描述】:

我正在编写代码以从图像捕获中检索经纬度。我可以使用相机事件和 onActivityResult 拍摄图像。

eprotected void onActivityResult(int requestCode, int resultCode, Intent data) {
    Uri _uri = null;
    Cursor cursor = null;

    try {
        final int PICK_IMAGE = 1;
        if (requestCode == PICK_IMAGE && data != null
                && data.getData() != null) {
            _uri = data.getData();

            if (_uri != null) {
                // User had pick an image.
                cursor = getContentResolver()
                        .query(_uri,
                                new String[] { android.provider.MediaStore.Images.ImageColumns.DATA },
                                null, null, null);
                cursor.moveToFirst();

                // Link to the image
                final String imageFilePath = cursor.getString(0);
                // Toast.makeText(getApplicationContext(), imageFilePath,
                // Toast.LENGTH_LONG).show();
                imageLocation= imageFilePath;

                File imgFile = new File(imageFilePath);
                if (imgFile.exists()) {
                    Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
                    captureImage.setImageBitmap(myBitmap);

                }
                cursor.close();
            } else {

                // Toast.makeText(getApplicationContext(), getSdCard,
                // Toast.LENGTH_LONG).show();
            }
        }
        super.onActivityResult(requestCode, resultCode, data);
    } catch (Exception e) {
        if (cursor == null || cursor.equals("")) {
            String getSdCard = _uri.getPath();
            imageLocation= getSdCard;
            File imgFile = new File(getSdCard);
            if (imgFile.exists()) {

                Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());

                captureImage.setImageBitmap(myBitmap);

            }
        }
        e.printStackTrace();
    }
}

从这里我们如何从图像中获得纬度和经度。我搜索了一段时间,我无法获得位置。

【问题讨论】:

  • 从图像中“获取经纬度”是什么意思?有人会使用LocationManager 来获取该信息,但这与位置无关。
  • 你是说拍照时获取当前设备的位置吗?
  • 我不确定,相机是否捕获带有经纬度位置的图像。我是这个话题的新手。
  • 您只能使用 gps 和/或 wi-fi 获取位置,因此,如果在拍摄照片的地方启用了这些功能,那么您可以使用 LocationManager 获取经纬度,但如果您的意思是获取通过分析该图像的经纬度,它应该非常困难
  • 伙计,你想从图像中获取 lat lng 吗?你的问题是什么意思?

标签: android android-location


【解决方案1】:

Monkeyless 的建议是对的,使用 Exifinterface。这里接受的答案中有一个工作示例:

How to get the latititude and longitude of an image in sdcard to my application?

【讨论】:

  • 感谢您的参考。我还有一个问题要问,是否可以务实地打开相机设置。我搜索了一段时间,无法获得适当的指导。你能帮忙吗?请
  • 如果我想到什么我会把它添加到你的另一个问题中:stackoverflow.com/questions/17715583/…
【解决方案2】:

相机可能会或可能不会随图像捕获位置数据,这取决于用户的相机应用程序和他们使用的任何设置(您可以禁用地理标记照片,默认情况下在大多数 Android 手机上它是禁用的)。如果图像附加了任何位置数据,您可以使用带有图像路径的ExifInterface 或使用MediaStore.Images.Media database 使用lat/lng columns 找到它。

您永远无法保证您将始终获得任何照片的位置数据。提供程序(gps/wifi/cell)可能被禁用,地理标记可能被禁用,即使两者都启用,手机也可能无法获取足够近且足够准确的地理点。

【讨论】:

    【解决方案3】:

    当您通过移动设备拍摄图像时,它通常仅使用拍摄时刻的日期和时间将图像保存在您的手机上。如果要为图片添加坐标,则必须在捕获期间使用 Android 中的 LocationManager 类。通过这个,您可以获得捕获的图像的长/纬度坐标。

    LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
    

    请注意,如果你想使用上面的sn-p,你必须在Android清单文件中包含下一个权限

    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    

    在这里阅读更多:android location strategies

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多