title: How to extract GPS location from HEIC files?
body: <p>I use the following code to extract GPS location both from JPG and HEIC files:</p>
  <pre><code>#coding=utf-8
  from PIL import Image
  from urllib.request import urlopen
  from PIL.ExifTags import TAGS
  from PIL.ExifTags import GPSTAGS
  
  from pillow_heif import register_heif_opener
  
  def get_exif(filename):
      image = Image.open(filename)
      image.verify()
      return image._getexif()
  
  def get_geotagging(exif):
      if not exif:
          raise ValueError(&quot;No EXIF metadata found&quot;)
  
      geotagging = {}
      for (idx, tag) in TAGS.items():
          if tag == 'GPSInfo':
              if idx not in exif:
                  raise ValueError(&quot;No EXIF geotagging found&quot;)
  
              for (key, val) in GPSTAGS.items():
                  if key in exif[idx]:
                      geotagging[val] = exif[idx][key]
  
      return geotagging
  
  register_heif_opener()
  
  my_image='IMG_9610.HEIC'
  #my_image='IMG_20210116_215317.jpg'
  
  exif = get_exif(my_image)
  labeled = get_geotagging(exif)
  print(labeled)
  </code></pre>
  <p>This code works well with JPEG files, but returns the following error with HEIC:</p>
  <pre><code>AttributeError: _getexif
  </code></pre>
  <p>If I add the following function</p>
  <pre><code>def get_labeled_exif(exif):
      labeled = {}
      for (key, val) in exif.items():
          labeled[TAGS.get(key)] = val
  
      return labeled
  </code></pre>
  <p>and replace '_getexif()' with 'getexif()' then it works for both files, but the data is encrypted there - <code>'GPSInfo': 1234</code> and <code>get_geotagging()</code> doesn't work for such exif.</p>
  <p>How could I fix it?</p>