Follow
Java PDF Blog
  • Click to learn more about PDF files
Amy Pearson Amy is a Java developer and member of the support team. Her main technical interests are JavaFX and Cloud. Out of hours she enjoys gaming and Virtual reality.

How to extract GPS data from image files in Java

May 24, 2023 52 sec read

What is Image GPS data?

Global Positioning System (GPS) data is the latitude and longitude coordinates that can be linked to the image. It is a part of an image’s metadata and usually, it is used to record where the picture was taken/created. Most phones nowadays automatically attach the GPS data to the images you take.

Where can I find it?

It is a part of the EXIF data, which is the metadata of an image. It can be found in the following image formats HEIC, JPEG, PNG, TIFF, WEBP. You can easily view the metadata in an image, you most likely have found it before when clicking to look for more information when viewing an image. In our JDeli Viewer, you can easily find it here.

How can I extract Image GPS data in Java?

There are many ways you can extract this data from the image in Java. You can use ImageIO, Apache Tika or our JDeli library.
They all give an easy and simple way to extract the metadata in just one or a few lines of code.

With JDeli:

JDeli.getImageInfo(byte[] data);

With Tika:

final ImageDetector detector = new ImageDetector();
detector.detect(TikaInputStream.get(Paths.get("file.img")), null);

With ImageIO:

ImageReader imageReader = ImageIO.getImageReadersByFormatName("ImageFormat").next();
imageReader.setInput(ImageIO.createImageInputStream(new ByteArrayInputStream(byte[] data)), true);

IIOMetadata metadata = imageReader.getImageMetadata(0);

 

You can find out more about handling metadata with our JDeli Image Library over on our support site.



Download your JDeli guide:

How to read, write and process common image file Formats in Java with JDeli

Start reading and writing images with one line of code

Read: BufferedImage image = JDeli.read(streamOrFile);

Write: JDeli.write(myBufferedImage, OutputFormat.HEIC, outputStreamOrFile)

Learn more >>

Amy Pearson Amy is a Java developer and member of the support team. Her main technical interests are JavaFX and Cloud. Out of hours she enjoys gaming and Virtual reality.
  • Image
  • JDeli
« What is tagged PDF?
Introducing our free guide on how to read and write images in Java with JDeli »

Comparing WebP compression algorithms

Amy Pearson
Nov 20, 2023 1 min read

How to read PDF files in Java?

Promil
Nov 10, 2023 1 min read

CCITT Compression Guide

Promil
Nov 6, 2023 1 min read

IDRsolutions Ltd 2023. All rights reserved.