2

I am writing code to retrieve lat and long from image capture. I can able to take image using camera event and 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();
    }
}

From this how come we get the latitude and longitude from the image. i searched a while, i cant able to get the location.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Ram
  • 83
  • 1
  • 3
  • 11
  • What do you mean "get the latitude and longitude" from image? One would use `LocationManager` to get that info, but that has nothing to do with location. – gunar Jul 17 '13 at 14:06
  • Did you mean get location of current device when taking the picture? – wtsang02 Jul 17 '13 at 14:06
  • I am not sure, does camera capture image with latitude and longitude location. i am new to this topic. – Ram Jul 17 '13 at 14:08
  • you can get the location only with gps and/or wi-fi so, if these are enabled at the place where photo is taken then you can get lat and long with LocationManager, but if you mean get lat and long by analysing that image, it should extremely hard – Onur A. Jul 17 '13 at 14:13
  • Dude, u want lat lng from a image ? What does your question mean ? – taxeeta Jul 17 '13 at 14:16
  • or is it possible something relates "TAG_GPS_LATITUDE" or "TAG_GPS_LONGITUDE". I mean getting tagged lat long from image. – Ram Jul 17 '13 at 14:17

3 Answers3

1

The camera may or may not capture location data with the image, that depends on the user's camera app and whatever settings they are using (you can disable geo tagging photos, by default on most android phones it is disabled). If any location data is attached to the image, you can find it either using ExifInterface with the path to the image, or using the MediaStore.Images.Media database using the lat/lng columns.

You can never guarantee that you will always get location data for any photo. Providers (gps/wifi/cell) might be disabled, geo tagging might be disabled, and even if both are enabled, the phone may not be able to acquire a recent enough and accurate enough geo point.

Sam Judd
  • 7,317
  • 1
  • 38
  • 38
1

What Monkeyless suggested is right, use the Exifinterface. There is a working example in the accepted answer to here:

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

Community
  • 1
  • 1
Chilledrat
  • 2,593
  • 3
  • 28
  • 38
  • Thanks for your reference. I have one more question to ask, is it possible to open the camera setting pragmatically. I searched for a while, cant able to get proper guidance. Can you help for this. pl – Ram Jul 18 '13 at 06:59
  • If I think of anything I'll add it to your other question: http://stackoverflow.com/questions/17715583/enable-camera-settings-android – Chilledrat Jul 19 '13 at 14:44
0

When you are capturing an image through your mobile device, it usually use only the date and time of the captured moment to save the image on your mobile. If you want to add coordinates to the picture, you have to use the LocationManager class from Android during the capture. By this you can obtain the long/lat coordinates of a captured image.

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

Please note that you have to include the next permission in the Android manifest file if you want to use the above snippet

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

read more here : android location strategies

KarelG
  • 5,176
  • 4
  • 33
  • 49