您現在的位置是:首頁 > 藝術
別發照片騙技術人
電腦怎麼查經緯度座標
序
今早看到CSDN裡推薦的Python獲取女朋友發來加班拍照定位地址是酒店的段子,本來準備驗證下,順便練練手的,最後安裝執行pip install json報沒有指定版本號。一怒之下搞我大JAVA,驗證可行與場景體遐想。廢話不多說,先上硬貨。
一、依賴匯入
從博文上看是exifread模組,找我大java的對應的jar,發現metadata-extractor,而且官方還在持續更新,最近的jar是今年的。
這個元資料提取jar非常強大,還支援影片資訊的提取,看看官方介紹:
看到沒,第一個示例,就寫的支援我大JAVA,讓我猶如雞血衝頂,在支援同事聯調事件工單的同時,大肝這塊。
<
dependency
>
<
groupId
>
com
。
drewnoakes
<
/
groupId
>
<
artifactId
>
metadata
-
extractor
<
/
artifactId
>
<
version
>
2。16
。0
<
/
version
>
<
/
dependency
>
二、準備工作
1、室外空曠地點開啟GPS
2、百度地圖、北斗伴驗證已連線到GPS定位
3、設定手機帶的照相機開啟位置資訊
4、拍照一張順便檢視照片詳情
這裡一定要確定拍的照片的詳情時有經緯度資訊的,如果沒有,你針對你的手機在CSDN裡搜尋下怎麼設定。這裡順便提下,CSDN的瀏覽器外掛真香。簡直就是我們技術人事的福音,再以不用擔心某某度的廣告之類導致找東西費勁了,而且它很包容,還時可以選擇自己喜歡的搜尋引擎的。
三、示例demo
這裡先演示這個元資料提取jar能提取到的資訊,順便把取到的經緯度透過百度轉地址。
因為是demo,沒有業務,我這裡就直接在測試類裡幹了。沒有什麼業務,不涉及什麼機密,可以上全碼。
package
com
。
easylinkin
。
bm
。
extractor
;
import
com
。
alibaba
。
fastjson
。
JSONObject
;
import
com
。
drew
。
imaging
。
ImageMetadataReader
;
import
com
。
drew
。
imaging
。
ImageProcessingException
;
import
com
。
drew
。
metadata
。
Directory
;
import
com
。
drew
。
metadata
。
Metadata
;
import
com
。
drew
。
metadata
。
Tag
;
import
com
。
easylinkin
。
bm
。
util
。
HttpUtils
;
import
lombok
。
extern
。
slf4j
。
Slf4j
;
import
java
。
io
。
File
;
import
java
。
io
。
IOException
;
/** * @author zhengwen **/
@Slf4j
public
class
ImgTestCode
{
public
static
void
main
(
String
[
]
args
)
throws
Exception
{
File
file
=
new
File
(
“C:\\Users\\zhengwen\\Desktop\\test\\IMG_20210820_093958。jpg”
)
;
readImageInfo
(
file
)
;
}
/** * 提取照片裡面的資訊 * * @param file 照片檔案 * @throws ImageProcessingException * @throws Exception */
private
static
void
readImageInfo
(
File
file
)
throws
ImageProcessingException
,
Exception
{
Metadata
metadata
=
ImageMetadataReader
。
readMetadata
(
file
)
;
System
。
out
。
println
(
“——-列印全部詳情——-”
)
;
for
(
Directory
directory
:
metadata
。
getDirectories
(
)
)
{
for
(
Tag
tag
:
directory
。
getTags
(
)
)
{
System
。
out
。
format
(
“[%s] - %s = %s\n”
,
directory
。
getName
(
)
,
tag
。
getTagName
(
)
,
tag
。
getDescription
(
)
)
;
}
if
(
directory
。
hasErrors
(
)
)
{
for
(
String
error
:
directory
。
getErrors
(
)
)
{
System
。
err
。
format
(
“ERROR: %s”
,
error
)
;
}
}
}
System
。
out
。
println
(
“——列印常用資訊——-”
)
;
Double
lat
=
null
;
Double
lng
=
null
;
for
(
Directory
directory
:
metadata
。
getDirectories
(
)
)
{
for
(
Tag
tag
:
directory
。
getTags
(
)
)
{
String
tagName
=
tag
。
getTagName
(
)
;
//標籤名
String
desc
=
tag
。
getDescription
(
)
;
//標籤資訊
if
(
tagName
。
equals
(
“Image Height”
)
)
{
System
。
err
。
println
(
“圖片高度: ”
+
desc
)
;
}
else
if
(
tagName
。
equals
(
“Image Width”
)
)
{
System
。
err
。
println
(
“圖片寬度: ”
+
desc
)
;
}
else
if
(
tagName
。
equals
(
“Date/Time Original”
)
)
{
System
。
err
。
println
(
“拍攝時間: ”
+
desc
)
;
}
else
if
(
tagName
。
equals
(
“GPS Latitude”
)
)
{
System
。
err
。
println
(
“緯度 : ”
+
desc
)
;
System
。
err
。
println
(
“緯度(度分秒格式) : ”
+
pointToLatlong
(
desc
)
)
;
lat
=
latLng2Decimal
(
desc
)
;
}
else
if
(
tagName
。
equals
(
“GPS Longitude”
)
)
{
System
。
err
。
println
(
“經度: ”
+
desc
)
;
System
。
err
。
println
(
“經度(度分秒格式): ”
+
pointToLatlong
(
desc
)
)
;
lng
=
latLng2Decimal
(
desc
)
;
}
}
}
System
。
err
。
println
(
“——經緯度轉地址——”
)
;
//經緯度轉地主使用百度api
convertGpsToLoaction
(
lat
,
lng
)
;
}
/** * 經緯度格式 轉換為 度分秒格式 ,如果需要的話可以呼叫該方法進行轉換 * * @param point 座標點 * @return */
public
static
String
pointToLatlong
(
String
point
)
{
Double
du
=
Double
。
parseDouble
(
point
。
substring
(
0
,
point
。
indexOf
(
“°”
)
)
。
trim
(
)
)
;
Double
fen
=
Double
。
parseDouble
(
point
。
substring
(
point
。
indexOf
(
“°”
)
+
1
,
point
。
indexOf
(
“‘”
)
)
。
trim
(
)
)
;
Double
miao
=
Double
。
parseDouble
(
point
。
substring
(
point
。
indexOf
(
“’”
)
+
1
,
point
。
indexOf
(
“\”“
)
)
。
trim
(
)
)
;
Double
duStr
=
du
+
fen
/
60
+
miao
/
60
/
60
;
return
duStr
。
toString
(
)
;
}
/*** * 經緯度座標格式轉換(* °轉十進位制格式) * @param gps */
public
static
double
latLng2Decimal
(
String
gps
)
{
String
a
=
gps
。
split
(
”°“
)
[
0
]
。
replace
(
” “
,
”“
)
;
String
b
=
gps
。
split
(
”°“
)
[
1
]
。
split
(
”‘“
)
[
0
]
。
replace
(
” “
,
”“
)
;
String
c
=
gps
。
split
(
”°“
)
[
1
]
。
split
(
”’“
)
[
1
]
。
replace
(
” “
,
”“
)
。
replace
(
”\“”
,
“”
)
;
double
gps_dou
=
Double
。
parseDouble
(
a
)
+
Double
。
parseDouble
(
b
)
/
60
+
Double
。
parseDouble
(
c
)
/
60
/
60
;
return
gps_dou
;
}
/** * api_key:註冊的百度api的key * coords:經緯度座標 * http://api。map。baidu。com/reverse_geocoding/v3/?ak=“+api_key+”&output=json&coordtype=wgs84ll&location=“+coords *
* 經緯度轉地址資訊 * * @param gps_latitude 維度 * @param gps_longitude 精度 */
private
static
void
convertGpsToLoaction
(
double
gps_latitude
,
double
gps_longitude
)
throws
IOException
{
String
apiKey
=
”YNxcSCAphFvuPD4LwcgWXwC3SEZZc7Ra“
;
String
res
=
”“
;
String
url
=
”http://api。map。baidu。com/reverse_geocoding/v3/?ak=“
+
apiKey
+
”&output=json&coordtype=wgs84ll&location=“
+
(
gps_latitude
+
”,“
+
gps_longitude
)
;
System
。
err
。
println
(
”【url】“
+
url
)
;
res
=
HttpUtils
。
httpGet
(
url
)
;
JSONObject
object
=
JSONObject
。
parseObject
(
res
)
;
if
(
object
。
containsKey
(
”result“
)
)
{
JSONObject
result
=
object
。
getJSONObject
(
”result“
)
;
if
(
result
。
containsKey
(
”addressComponent“
)
)
{
JSONObject
address
=
object
。
getJSONObject
(
”result“
)
。
getJSONObject
(
”addressComponent“
)
;
System
。
err
。
println
(
”拍攝地點:“
+
address
。
get
(
”country“
)
+
” “
+
address
。
get
(
”province“
)
+
” “
+
address
。
get
(
”city“
)
+
” “
+
address
。
get
(
”district“
)
+
” “
+
address
。
get
(
”street“
)
+
” “
+
result
。
get
(
”formatted_address“
)
+
” “
+
result
。
get
(
”business“
)
)
;
}
}
}
}
控制檯列印:
下面貼出詳細內容:
com
。
easylinkin
。
bm
。
extractor
。
ImgTestCode
——
-
列印全部詳情
——
-
[
JPEG
]
-
Compression
Type
=
Baseline
[
JPEG
]
-
Data
Precision
=
8
bits
[
JPEG
]
-
Image
Height
=
4032
pixels
[
JPEG
]
-
Image
Width
=
3024
pixels
[
JPEG
]
-
Number
of
Components
=
3
[
JPEG
]
-
Component
1
=
Y
component
:
Quantization
table
0
,
Sampling
factors
2
horiz
/
2
vert
[
JPEG
]
-
Component
2
=
Cb
component
:
Quantization
table
1
,
Sampling
factors
1
horiz
/
1
vert
[
JPEG
]
-
Component
3
=
Cr
component
:
Quantization
table
1
,
Sampling
factors
1
horiz
/
1
vert
[
Exif
IFD0
]
-
Date
/
Time
=
2021
:
08
:
20
09
:
39
:
58
[
Exif
IFD0
]
-
Model
=
YOTA Y3
[
Exif
IFD0
]
-
YCbCr
Positioning
=
Center
of pixel array
[
Exif
IFD0
]
-
Resolution
Unit
=
Inch
[
Exif
IFD0
]
-
Y
Resolution
=
72
dots per inch
[
Exif
IFD0
]
-
X
Resolution
=
72
dots per inch
[
Exif
IFD0
]
-
Make
=
YOTA
[
GPS
]
-
GPS
Date
Stamp
=
2021
:
08
:
20
[
GPS
]
-
GPS
Altitude
Ref
=
Below
sea level
[
GPS
]
-
GPS
Longitude
Ref
=
E
[
GPS
]
-
GPS
Longitude
=
114
°
24
‘
9。61
”
[
GPS
]
-
GPS
Processing
Method
=
ASCII
[
GPS
]
-
GPS
Latitude
Ref
=
N
[
GPS
]
-
GPS
Time
-
Stamp
=
01
:
39
:
46。000
UTC
[
GPS
]
-
GPS
Altitude
=
21
metres
[
GPS
]
-
GPS
Latitude
=
30
°
28
’
40。67
“
[
Exif
SubIFD
]
-
Color
Space
=
sRGB
[
Exif
SubIFD
]
-
F
-
Number
=
f
/
1。9
[
Exif
SubIFD
]
-
Date
/
Time
Digitized
=
2021
:
08
:
20
09
:
39
:
58
[
Exif
SubIFD
]
-
Focal
Length
=
3。9
mm
[
Exif
SubIFD
]
-
Aperture
Value
=
f
/
1。9
[
Exif
SubIFD
]
-
Exposure
Mode
=
Auto
exposure
[
Exif
SubIFD
]
-
Sub
-
Sec
Time
Digitized
=
819350
[
Exif
SubIFD
]
-
Exif
Image
Height
=
4032
pixels
[
Exif
SubIFD
]
-
Focal
Length
35
=
23
mm
[
Exif
SubIFD
]
-
Scene
Capture
Type
=
Standard
[
Exif
SubIFD
]
-
Sub
-
Sec
Time
Original
=
819350
[
Exif
SubIFD
]
-
Exposure
Program
=
Unknown
(
0
)
[
Exif
SubIFD
]
-
White
Balance
Mode
=
Auto
white balance
[
Exif
SubIFD
]
-
Exif
Image
Width
=
3024
pixels
[
Exif
SubIFD
]
-
Sub
-
Sec
Time
=
819350
[
Exif
SubIFD
]
-
Shutter
Speed
Value
=
1
/
1022
sec
[
Exif
SubIFD
]
-
Metering
Mode
=
Center
weighted average
[
Exif
SubIFD
]
-
Date
/
Time
Original
=
2021
:
08
:
20
09
:
39
:
58
[
Exif
SubIFD
]
-
Components
Configuration
=
YCbCr
[
Exif
SubIFD
]
-
Exif
Version
=
2。20
[
Exif
SubIFD
]
-
Flash
=
Flash
did not fire
[
Exif
SubIFD
]
-
Brightness
Value
=
0。0
[
Exif
SubIFD
]
-
ISO
Speed
Ratings
=
103
[
Exif
SubIFD
]
-
Sensing
Method
=
One
-
chip color area sensor
[
Exif
SubIFD
]
-
FlashPix
Version
=
1。00
[
Exif
SubIFD
]
-
Exposure
Time
=
1
/
1023
sec
[
Interoperability
]
-
Interoperability
Index
=
Recommended
Exif
Interoperability
Rules
(
ExifR98
)
[
Interoperability
]
-
Interoperability
Version
=
1。00
[
Exif
Thumbnail
]
-
Y
Resolution
=
72
dots per inch
[
Exif
Thumbnail
]
-
Thumbnail
Length
=
21538
bytes
[
Exif
Thumbnail
]
-
Thumbnail
Offset
=
959
bytes
[
Exif
Thumbnail
]
-
Compression
=
JPEG
(
old
-
style
)
[
Exif
Thumbnail
]
-
Resolution
Unit
=
Inch
[
Exif
Thumbnail
]
-
X
Resolution
=
72
dots per inch
[
Huffman
]
-
Number
of
Tables
=
4
Huffman
tables
[
File
Type
]
-
Detected
File
Type
Name
=
JPEG
[
File
Type
]
-
Detected
File
Type
Long
Name
=
Joint
Photographic
Experts
Group
[
File
Type
]
-
Detected
MIME
Type
=
image
/
jpeg
[
File
Type
]
-
Expected
File
Name
Extension
=
jpg
[
File
]
-
File
Name
=
IMG_20210820_093958
。
jpg
[
File
]
-
File
Size
=
5215044
bytes
[
File
]
-
File
Modified
Date
=
星期五 八月
20
09
:
39
:
59
+
08
:
00
2021
——
列印常用資訊
——
-
初始化
HttpClientTest
~
~
~
開始圖片高度
:
4032
pixels圖片寬度
:
3024
pixels經度
:
114
°
24
‘
9。61
”經度
(
度分秒格式
)
:
114。40266944444446
緯度
:
30
°
28
’
40。67
“緯度
(
度分秒格式
)
:
30。477963888888887
拍攝時間
:
2021
:
08
:
20
09
:
39
:
58
——
經緯度轉地址
——
【url】http
:
/
/
api
。
map
。
baidu
。
com
/
reverse_geocoding
/
v3
/
?
ak
=
YNxcSCAphFvuPD4LwcgWXwC3SEZZc7Ra
&
output
=
json
&
coordtype
=
wgs84ll
&
location
=
30。477963888888887
,
114。40266944444446
初始化
HttpClientTest
~
~
~
結束拍攝地點:中國 湖北省 武漢市 洪山區 軟體園路 湖北省武漢市洪山區軟體園路
9
關山
,
光谷天地
上面的提取到的內容我就不解釋了,應該看得懂,不懂的,可以翻譯英文,或者查API看列印的是啥。
其他檔案我就不演示了,有興趣的可以自己試試。
我的百度地圖的AK就先放這裡,方便大家驗證,免得說我騙人,反正我也是免費用的。
最後再說一句,圖片傳送要麼壓縮到壓縮包再發送,要麼用資料線從手機裡拷出來。我這裡先用微信發的,基本上資訊都被抹除了(在電腦上檢視圖片詳情,其實也可以看到經緯度資訊的)。
還有,我還有個蘋果手機,其實也是可以拍有地理位置資訊的照片的,要開啟隱私裡的定位,授權照相機。
四、總結與衍生想法
這個怎麼說呢,還是很不錯的。用到我們的工作中的話,我們覺得可以替代我們之前做的一個打點巡檢的,到達巡檢位置拍張照片再配合機器碼,不不怕讓你讓別人代拍照片了。還有考勤的公出單、外勤等等。
另外還想到這出門在外愛拍照的娃們,你們的照片放到雲端儲存上,然後如果有無良服務商,基本可以把你的軌跡透過你上傳的照片時間繪製出來……
好了,這個就分享到這裡。這裡其實還給我一個最大的感受就是,如果我不知道A就不會想到B。要是我早知道圖片可以攜帶的資訊,或者知道照相機軟體可以獲取的資訊,可能可以針對這些早點做點什麼……
,https://blog。csdn。net/zwrlj527/article/details/119823407
推薦文章
- 吃播內幕:龍蝦是道具,火鍋底料是蛋糕,最後才發現,都是自找的
現在是一個網路的時代,那麼也有很多的人他們都知道現在網路直播也是非常火爆的,這是對於現在的人們來說,已經開始比較依賴網路了,也有很多的人,他們都會發現我們經常在沒事情的時候都會在手機上面看到各種各樣的平臺,這些平臺出現了很多網路直播,在我們...
- 鬥式提升機遇見這些問題怎麼辦
三、降低鬥式提升機機殼內異常噪音機殼內出現異常噪音一般是由於料斗脫落、損壞和鬆動造成的,裝置出現此種情況需要立即停機並修復...
- 在大相嶺深處(逐夢)
三順著周德祥手指的方向,我來到山勢愈險、林木更密的大熊貓國家公園滎經縣管護總站,這也是九〇後付明霞工作了七年的地方...