这是我的代码,用于为Google Takeout json文件中的照片添加GPS:
if __name__ == '__main__':
from sys import argv
opt = OptionParser()
opt.add_option('-l', '--location')
# not sure what this timezone offset is because before
# day light saving it was set to 0 and was working maybe it time shift
opt.add_option('-t', '--timezone')
(options, args) = opt.parse_args()
if options.location is None or len(args) != 1:
print "usage %s [--timezone <hours shift>] --location [History JSON File] <IMAGE FILE>" % argv[0]
else:
gps_list = json.loads(open(options.location).read())
date = parse_date(get_date_taken(args[0]))
if options.timezone is not None:
loc = get_gps(gps_list, date, -float(options.timezone))
else:
loc = get_gps(gps_list, date)
found = datetime.fromtimestamp(
int(loc['timestampMs']) / 1000.0
)
print "%s == %s" % (date, found)
# this conversion seems to be correct (get it from other SO question)
print loc
print "lat: %s" % str(int(loc['latitudeE7']) / 1e7)
print "long: %s" % str(int(loc['longitudeE7']) / 1e7)
call([
'exiftool',
'-m',
'-GPSLatitude=%s' % str(int(loc['latitudeE7']) / 1e7),
'-GPSLongitude=%s' % str(int(loc['longitudeE7']) / 1e7),
args[0]
])
我已经检查了this GPS checker处单张照片的输出,该位置大约是正确的,但是当我将GPS添加到图片并将其上传到pic2map.com时,距离已经很近了(几公里)在另一个方向)。
您是否知道其他任何GPS位置检查器,可能pic2map不正确并显示错误位置。还是exif工具接受不同的数据。如果是这样,我该如何校正exif工具数据以获得正确的GPS定位照片。 (我主要是想为flickr安装GPS,因此将其添加到GPS定位服务中可以正确搜索GPS。)
编辑:
外卖json看起来像这样:
{
"locations" : [ {
"timestampMs" : "1406974281661",
"latitudeE7" : 511162000,
"longitudeE7" : 208802232,
"accuracy" : 19
}, {
"timestampMs" : "1406974327231",
"latitudeE7" : 511161756,
"longitudeE7" : 208801345,
"accuracy" : 7
}, {
"timestampMs" : "1406974373278",
"latitudeE7" : 511161741,
"longitudeE7" : 208801377,
"accuracy" : 7,
"activity" : [ {
"timestampMs" : "1406974371946",
"activity" : [ {
"type" : "IN_VEHICLE",
"confidence" : 63
}, {
"type" : "STILL",
"confidence" : 37
} ]
} ]
}
...
}, {
"timestampMs" : "1556810257251",
"latitudeE7" : 511051671,
"longitudeE7" : 207460199,
"accuracy" : 9,
"velocity" : 0,
"altitude" : 323,
"verticalAccuracy" : 33
} ]
}