{"id":28,"date":"2012-11-11T13:18:29","date_gmt":"2012-11-11T11:18:29","guid":{"rendered":"http:\/\/www.hurmuzov.com\/?p=28"},"modified":"2012-11-11T13:18:29","modified_gmt":"2012-11-11T11:18:29","slug":"get-geo-location-from-image-file","status":"publish","type":"post","link":"https:\/\/www.hurmuzov.com\/?p=28","title":{"rendered":"Get Geo Location from Image File"},"content":{"rendered":"<p>&nbsp;<\/p>\n<pre>public static GeoLocation getMetadata(String filename) {\r\n\u00a0\u00a0 \u00a0GeoLocation gl = null;\r\n\r\n\u00a0\u00a0 \u00a0try {\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0File file = new File(filename);\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0Metadata metadata = ImageMetadataReader.readMetadata(file);\r\n\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0for (Directory directory : metadata.getDirectories()) {\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0if (directory instanceof GpsDirectory) {\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0GpsDirectory gpsd = (GpsDirectory)directory;\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0gl = gpsd.getGeoLocation();\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0}\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0}\r\n\r\n\u00a0\u00a0 \u00a0} catch (ImageProcessingException | IOException ex) {\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0Logger.getLogger(ImageHelper.class.getName()).log(Level.SEVERE, null, ex);\r\n\u00a0\u00a0 \u00a0}\r\n\u00a0\u00a0 \u00a0return gl;\r\n}<\/pre>\n<p>&nbsp;<\/p>\n<p>Very simple.<br \/>\nThe example uses metadata extractor in Java.<br \/>\nhttp:\/\/www.drewnoakes.com\/code\/exif\/<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; public static GeoLocation getMetadata(String filename) { \u00a0\u00a0 \u00a0GeoLocation gl = null; \u00a0\u00a0 \u00a0try { \u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0File file = new File(filename); \u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0Metadata metadata = ImageMetadataReader.readMetadata(file); \u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0for (Directory directory : metadata.getDirectories()) { \u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0if (directory instanceof GpsDirectory) { \u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0GpsDirectory gpsd = (GpsDirectory)directory; \u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"footnotes":""},"categories":[6,3],"tags":[],"_links":{"self":[{"href":"https:\/\/www.hurmuzov.com\/index.php?rest_route=\/wp\/v2\/posts\/28"}],"collection":[{"href":"https:\/\/www.hurmuzov.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hurmuzov.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hurmuzov.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hurmuzov.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=28"}],"version-history":[{"count":5,"href":"https:\/\/www.hurmuzov.com\/index.php?rest_route=\/wp\/v2\/posts\/28\/revisions"}],"predecessor-version":[{"id":33,"href":"https:\/\/www.hurmuzov.com\/index.php?rest_route=\/wp\/v2\/posts\/28\/revisions\/33"}],"wp:attachment":[{"href":"https:\/\/www.hurmuzov.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=28"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hurmuzov.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=28"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hurmuzov.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=28"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}