{"id":83,"date":"2023-03-09T15:21:38","date_gmt":"2023-03-09T15:21:38","guid":{"rendered":"https:\/\/smartsource.com.sg\/blog\/?p=83"},"modified":"2023-03-09T15:21:38","modified_gmt":"2023-03-09T15:21:38","slug":"java-program-to-get-location-from-an-image","status":"publish","type":"post","link":"https:\/\/smartsource.com.sg\/blog\/index.php\/2023\/03\/09\/java-program-to-get-location-from-an-image\/","title":{"rendered":"Java program to get location from an image"},"content":{"rendered":"\n<p>Here is the Java programs to get location metadata from an image using the metadata-extractor library in Java<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import java.io.File;\r\nimport java.io.IOException;\r\nimport java.util.Arrays;\r\nimport java.util.List;\r\n\r\nimport com.drew.imaging.ImageMetadataReader;\r\nimport com.drew.metadata.Directory;\r\nimport com.drew.metadata.Metadata;\r\nimport com.drew.metadata.Tag;\r\nimport com.drew.metadata.exif.GpsDirectory;\r\n\r\npublic class ImageLocation {\r\n    public static void main(String&#91;] args) throws IOException {\r\n        String imageFilePath = \"image.jpg\";\r\n        File imageFile = new File(imageFilePath);\r\n        Metadata metadata = ImageMetadataReader.readMetadata(imageFile);\r\n        GpsDirectory gpsDirectory = metadata.getFirstDirectoryOfType(GpsDirectory.class);\r\n        if (gpsDirectory != null &amp;&amp; gpsDirectory.getGeoLocation() != null) {\r\n            Double latitude = gpsDirectory.getGeoLocation().getLatitude();\r\n            Double longitude = gpsDirectory.getGeoLocation().getLongitude();\r\n            System.out.println(\"Latitude: \" + latitude);\r\n            System.out.println(\"Longitude: \" + longitude);\r\n        } else {\r\n            System.out.println(\"No location data found in image metadata.\");\r\n        }\r\n    }\r\n}\r\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Here is the Java programs to get location metadata from an image using the metadata-extractor library in Java<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[62,63],"class_list":["post-83","post","type-post","status-publish","format-standard","hentry","category-tutorials","tag-image","tag-location"],"_links":{"self":[{"href":"https:\/\/smartsource.com.sg\/blog\/index.php\/wp-json\/wp\/v2\/posts\/83","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/smartsource.com.sg\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/smartsource.com.sg\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/smartsource.com.sg\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/smartsource.com.sg\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=83"}],"version-history":[{"count":1,"href":"https:\/\/smartsource.com.sg\/blog\/index.php\/wp-json\/wp\/v2\/posts\/83\/revisions"}],"predecessor-version":[{"id":84,"href":"https:\/\/smartsource.com.sg\/blog\/index.php\/wp-json\/wp\/v2\/posts\/83\/revisions\/84"}],"wp:attachment":[{"href":"https:\/\/smartsource.com.sg\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=83"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/smartsource.com.sg\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=83"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/smartsource.com.sg\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=83"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}