Java program to get location meta data from an image
By: Manoj
Here is the Java program to get location metadata from an image using the metadata-extractor library in Java.
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import com.drew.imaging.ImageMetadataReader;
import com.drew.metadata.Directory;
import com.drew.metadata.Metadata;
import com.drew.metadata.Tag;
import com.drew.metadata.exif.GpsDirectory;
public class ImageLocation {
public static void main(String[] args) throws IOException {
String imageFilePath = "image.jpg";
File imageFile = new File(imageFilePath);
Metadata metadata = ImageMetadataReader.readMetadata(imageFile);
GpsDirectory gpsDirectory = metadata.getFirstDirectoryOfType(GpsDirectory.class);
if (gpsDirectory != null && gpsDirectory.getGeoLocation() != null) {
Double latitude = gpsDirectory.getGeoLocation().getLatitude();
Double longitude = gpsDirectory.getGeoLocation().getLongitude();
System.out.println("Latitude: " + latitude);
System.out.println("Longitude: " + longitude);
} else {
System.out.println("No location data found in image metadata.");
}
}
}
Archived Comments
Comment on this tutorial
- Data Science
- Android
- AJAX
- ASP.net
- C
- C++
- C#
- Cocoa
- Cloud Computing
- HTML5
- Java
- Javascript
- JSF
- JSP
- J2ME
- Java Beans
- EJB
- JDBC
- Linux
- Mac OS X
- iPhone
- MySQL
- Office 365
- Perl
- PHP
- Python
- Ruby
- VB.net
- Hibernate
- Struts
- SAP
- Trends
- Tech Reviews
- WebServices
- XML
- Certification
- Interview
categories
Related Tutorials
Java program to get location meta data from an image
Program using concept of byte long short and int in java
Update contents of a file within a jar file
Tomcat and httpd configured in port 8080 and 80
Count number of vowels, consonants and digits in a String in Java
Student marks calculation program in Java
Calculate gross salary in Java
Calculate average sale of the week in Java
Vector in Java - Sample Program