Hi, I’m Lex the Lex who likes to bully Superman

Last time, we used Python to read the GPS information of the photo. We could get the date of the photo, the model of the phone, and so on

Precise location of the location. Java indicates denial ~~~

Today’s focus: Using Java to read the time when the photo was taken, GPS location, phone model and other information

Take you step by step to achieve the function, the end of the article has a complete source oh

Here’s the thing

Today is the day to show my true colors

Using the best language in the world – Java (probably getting blasted)

To achieve a photo GPS this function

The general function is:

The photos are analyzed by the script and the location of the photos is located by GPS

In addition, you can also get information such as the shooting date and phone model.

The first effect

I found a photo posted by a beautiful woman from a wechat group

Java analyzes the photo as follows

The results are as follows:

{altitude =0 metres, phone =Xiaomi, latitude =24.41046111111111, model =MI MAX, longitude =103.41424722222223, shooting time =2018:12:01 16:37:32, Location = China in honghe hani and yi autonomous prefecture, yunnan province, maitreya, XXX, XXX road XXXX hotel} latitude and longitude: 24.41046111111111, 103.41424722222223 shooting time: 2018: at 12:01 16:37:32 phone models: Xiaomi MI MAX location: XXXX Hotel, No.XXX, XXX Road, Meili City, Honghe Hani and Yi Autonomous Prefecture, Yunnan Province, China {" status ": 0," result ": {" location" : {" LNG ": 103.42283328917563," lat ": 24.413805252378915}, "Formatted_address ":" Wenquan Road, Meili City, Honghe Hani and Yi Autonomous Prefecture, Yunnan Province "," Business ":"","addressComponent": {" country ", "Chinese", "country_code" : 0, "country_code_iso" : "CHN", "country_code_iso2" : "CN", "Province", "yunnan province", "city" : "honghe hani and yi autonomous prefecture," "city_level" : 2, "district" : "maitreya city", "town" : ""," town_code ":" ", "adcode" : "532504", "street" Road: "XXX," "street_number" : ""," direction ":" ", "short" : ""}," cityCode ": 107}}Copy the code

Emmm, it’s hard to describe too much

Java implementation method

1. Introduce relevant JAR packages

Here we need to introduce two JAR packages to read the exIF information for the photo, which contains the complete information for the photo.

Resource download, put it at the end.

2. Read the original Exif information

First, using the JAR package tool,

Read out the original Exif information in the photo.

The complete code is as follows:

public static HashMap<String, Object> readPicInfo(String file_path) { HashMap<String, Object> map = new HashMap<String,Object>(); Tag tag = null; File jpegFile = new File(file_path); Metadata metadata; try { metadata = JpegMetadataReader.readMetadata(jpegFile); Iterator<Directory> it = metadata.getDirectories().iterator(); while (it.hasNext()) { Directory exif = it.next(); Iterator<Tag> tags = exif.getTags().iterator(); while (tags.hasNext()) { tag = (Tag) tags.next(); System.out.println(tag.getTagName()+"--"+tag.getDescription()); } } } catch (JpegProcessingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return map; } public static void main(String[] args) {readPicInfo("C:\ Users\\pacer\ Desktop\ img\ others\ 10.jpg"); }Copy the code

Let’s see what information we can get:

Phone model taken, GPS precise location, shooting time, pixel, modification date

Even the elevation of the location was there.

3. GPS format conversion

The GPS information we read through exif is in a format similar to degrees, minutes, and seconds.

We need to compute the GPS information into decimal digits,

In this way, baidu Map API or other map API can be called to convert GPS information into geographic location information.

/*** * Longitude and latitude coordinate format conversion * @param Gps */ public double latitude_and_longitude_convert_to_decimal_system(String Gps) {String a = Gps. The split (" ° ") [0]. Replace (" ", ""); String b = Gps. The split (" ° ") [1]. The split (" '") [0]. Replace (" ", ""); String c = Gps. The split (" ° ") [1]. The split (" '") [1]. The replace (" ", ""). The replace (" \" ", ""); double gps_dou = Double.parseDouble(a)+Double.parseDouble(b)/60 + Double.parseDouble(c)/60/60; return gps_dou; }Copy the code

Using this function, we convert the latitude and longitude information to decimal numeric information.

4. Call map API to convert GPS coordinates to geographic location

What we get from exif raw information is a string of geographic coordinates.

If you want to convert to specific address information, you need to do this through the major map apis,

Users can register a Baidu Map API for free, and then call the interface provided by it.

You can convert the incoming GPS coordinates into address information. Of course, you can use mine here.

Call the interface method as follows:

//api_key: is your registered key value //coords: Is your latitude and longitude coordinates http://api.map.baidu.com/reverse_geocoding/v3/?ak= + api_key "+" & output = = json&coordtype wgs84ll & location = "+ coordsCopy the code

5. Complete code

Finally, put the code together.

Made a simple Java small project

With the Java environment, you can run ~~

【 Project complete code + complete JAR package 】

Download address:

Full project download address [with test photos]

Original download address

Deep work and name

Recommended reading

【Java Resources 】

  • [JDK5] jdk1.5×64-bit Windows. Zip
  • Download.csdn.net/download/we…
  • 【JDK6】 jdK-6U45-Windows-x64 JDk1.6 64-bit Windows version
  • Download.csdn.net/download/we…
  • 【JDK7】 JDK-7U72-windows-i586-32 bits
  • Download.csdn.net/download/we…
  • JDK – 8 JDK8 】 【 u131 – Linux – x64. Tar. Gz
  • Download.csdn.net/download/we…
  • JDK – 8 JDK8 】 【 u131 – Linux – x64. Tar. Gz
  • Download.csdn.net/download/we…

【python实战】

  • 【python实战】Ex-girlfriend wedding. Python hacked the WIFI at the wedding and changed the name
  • 【 Python Combat 】 my ex-girlfriend sent encryption “520 happy. PDF”, I use Python to crack open, but found
  • Last night, I used Python to take a selfie for my little sister next door.
  • Python boyfriend discovers a shocking secret with 30 lines of code
  • You’re so fucking stupid — you can record every move on a keyboard with 30 lines of code
  • 【pythonI forgot my password. I only wrote 20 lines of code in Python

Pygame development actual combat development 30 cases complete source code

  • Download.csdn.net/download/we…

Pygame Game development column, get the full source code + tutorial

  • Pygame game development 30 cases (2) — tower defense game
  • Come together to learn Pygame game development 30 cases (four) – Tetris small game
  • Practical column of penetration test
  • Windows AD/Exchange Management column
  • Linux high-performance server setup
  • PowerShell Automation column