0

How can I select an image from Android gallery and get the path + GPS data (lat & long)?

With the code below I don‘t get the path from the original image with GPS data. It returns a path to a cache file without GPS data. “/data/user/0/com.embarcadero.Project1/cache/IMG_20190319_[...].jpg” The original image is in “/DCIM/Camera/” and has another name.

How do I get the path from the original image?

procedure TForm2.FormCreate(Sender: TObject);
begin
  TMessageManager.DefaultManager.SubscribeToMessage(TMessageReceivedImagePath, DidReceiveBitmap);
end;

procedure TForm2.TakePhotoFromLibraryAction1DidCancelTaking;
begin
  //
end;

procedure TForm2.TakePhotoFromLibraryAction1DidFinishTaking(Image: TBitmap);
begin
  Image1.Bitmap := Image;
end;

procedure TForm2.DidReceiveBitmap(const Sender: TObject; const M: TMessage);
var
  LMessage: TMessageResultNotification;
  LImagePath: String;
begin
  if M is TMessageReceivedImagePath then
  begin
    LMessage := TMessageResultNotification(M);
    LImagePath := (M as TMessageReceivedImagePath).Value; // <--- '/data/user/0/com.embarcadero.Project1/cache/IMG_20190319_[...].jpg'
    if LMessage.RequestCode = TJFMXMediaLibrary.JavaClass.ACTION_TAKE_IMAGE_FROM_LIBRARY then
    begin
      GetEXIF(LImagePath);
      Image2.Bitmap.LoadFromFile(LImagePath);
    end;
  end;
end;

procedure TForm2.GetEXIF(const AFileName: String);
var
  LEXIF: JExifInterface;
  LLatLong: TJavaArray<Single>;
begin
  LEXIF := TJExifInterface.JavaClass.init(StringToJString(AFileName));
  Memo1.Lines.Add('File: ' + AFileName);
  LLatLong := TJavaArray<Single>.Create(2);
  if LEXIF.getLatLong(LLatLong) then
  begin
    Memo1.Lines.Add('Latitude: ' + LLatLong.Items[0].ToString);
    Memo1.Lines.Add('Longitude: ' + LLatLong.Items[1].ToString);
  end;
  LLatLong.Free;
end; 
Colin S
  • 1
  • 1
  • Possible duplicate of [How to read GPS Coordinates from JPG EXIF using CCR.EXIF in Delphi?](https://stackoverflow.com/questions/36383973/how-to-read-gps-coordinates-from-jpg-exif-using-ccr-exif-in-delphi) – Relinkvent Mar 22 '19 at 06:38
  • My problem is to get the path from the original picture. GetEXIF works fine. – Colin S Mar 22 '19 at 15:41
  • You should change the description of you problem then, since above you mentioned : "How can I select a picture from Android gallery and get the path + GPS data (lat & long)?, I get a path to a cached picture, without GPS data. " And as I understood it you wanted to get GPS Data, since you didnt mention you wanted to get the Data – Relinkvent Mar 26 '19 at 13:26

0 Answers0