0

This is my code for adding GPS for photos from Google Takeout json file:

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]
        ])

I've checked the output for single photo at this GPS checker and the location is about right, but when I've added GPS to the picture and uploaded it to pic2map.com it's way off (few km in other direction).

DO you know any other GPS location checker maybe pic2map is not correct and show wrong position. Or is exif tool accept different data. If so how can I correct the exif tool data to get correct GPS location of photos. (I mainly want to have GPS for flickr so it's added to GPS location services to have correct GPS to search for).

EDIT:

Takeout json look like this:

{
  "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
  } ]
}
jcubic
  • 61,973
  • 54
  • 229
  • 402
  • I can't comment on if the location is accurate or not, but here are a couple helpful details. First, when you set GPS coordinates, you also need to set the associated Ref tags (`GPSLatitudeRef`/`GPSLongitudeRef`). This is especially important if the location is in the Western or Southern hemisphere. Also, there's no need to parse the Json. Exiftool can read json and copy information directly. You can run `exiftool -s file.json` to see the names that you can copy from. See [this StackOverflow answer](https://stackoverflow.com/questions/42024255/bulk-join-json-with-jpg-from-google-takeout) – StarGeek May 02 '19 at 18:15
  • @StarGeek it don't work anymore, it just echo lots and lots of numbers (two digits) separated by commas. – jcubic May 02 '19 at 18:24
  • What version of exiftool are you using? That command should not echo a lot of numbers separated by commas, especially if you're using a version newer than 10.47. [Here's an example listing](https://pastebin.com/GzDZsJyV) from exiftool from the Google Takeout I just did. There are two types of GPS listings, the GeoDataExifLatitude/Longitude group that has the GPS coordinates in the file when uploaded (no data in this example) and the GeoDataLatitude/Longitude group which is the data inputted on Google Photos. Can you post an example JSON file (redact the URL line for privacy). – StarGeek May 02 '19 at 19:12
  • An example command would be `exiftool -TagsFromFile 2013-02-02.json "-GpsLatitude – StarGeek May 02 '19 at 19:12
  • @StarGeek got `0 image files updated 1 image files unchanged` and I have version 11.30 on GNU/Linux. Do you use latest takeout? it don't have any fields with Geo in them. – jcubic May 02 '19 at 19:23
  • Can you share the Json file? Redacting the URL for privacy. If you're not in the US, I suspect that the json data names might be different. – StarGeek May 02 '19 at 19:29
  • @StarGeek updated the question.first few entries and last one. (maybe my phone now have velocity and altitude that's why they are there in last entry). – jcubic May 02 '19 at 19:36
  • Yes, I just did a takeout. [Here's example json file](https://pastebin.com/RfPtqPVg) from the takeout. Are you using the json file that matches the image file (has the same name, different extension) or using the album json (`metadata.json`) or do you files have a different name? – StarGeek May 02 '19 at 19:36
  • Hmm… that json is very different. Exiftool can't parse that example as json. My apologies, I think I've wasted your time. – StarGeek May 02 '19 at 19:44

0 Answers0