Looking to take your VBA skills further?...

Discover twinBASIC — a powerful new development platform that expands on VBA and VB6 with advanced features, modern tools, and enhanced compatibility. Perfect for those ready to elevate their projects or transition from VBA, twinBASIC lets you build on what you already know and take your applications to the next level!

Try out twinBASIC Community Edition - it's free!

Extracting GPS data from JPEG files

        8 votes: *****     8,793 views      3 comments
by Wayne Phillips, 06 July 2012    (for Access 2000+)

The following Access database provides the ability to read GPS data stored in JPEG files.  Written as a set of VBA class modules, they may be included and used in any project royalty free provided they are not modified in any way.

GPSExifReader.zip

Unlike in Accessing detailed file information provided by the Operating System, this code is not dependant on Windows support for exposing the GPS data.  This version works in Operating Systems such as Windows XP which doesn't itself expose the GPS data found in JPEGs.

This work was commissioned by Australia's North Central Catchment Management Authority, written by Wayne Phillips.

Many thanks go to Australia's North Central Catchment Management Authority for allowing us to release this code publicly.

Usage Guide:

GPSExifReader class is the root object that exposes two methods:

   GPSExifReader.OpenFile(FilePath As String)

   GPSExifReader.BrowseAndOpenFile()

Both methods return an object of type GPSExifProperties for accessing the exposed Exif data.  Use
OpenFile method if you know the path of the file you wish to open.  Use BrowseAndOpenFile if you
don't know the file path and wish to be prompted with the typical Open-File dialog.

The following exceptions can be thrown when opening a file:

   ERROR_NO_EXIFDATA   (&H8004CAA0)       // File contains no EXIF data.
   ERROR_OPENFILE      (&H8004CAA1)       // Error opening file.  If file exists, check it is not opened exclusively in another program.
   ERROR_READFILE      (&H8004CAA2)       // Error parsing file.  File format invalid or not understood.
   E_FAIL_SANITYCHECK1 (&H8004CAA3)       // Failed sanity check.  Invalid JPEG file header.
   E_FAIL_SANITYCHECK2 (&H8004CAA4)       // Failed sanity check.  Non APP1 section Length not > 2 bytes (size of the length field).
   E_FAIL_SANITYCHECK3 (&H8004CAA5)       // Failed sanity check.  APP1 section header without 'Exif' sanity text.
   E_FAIL_SANITYCHECK4 (&H8004CAA6)       // Failed sanity check.  Tiff header without valid byte order characters.
   E_FAIL_SANITYCHECK5 (&H8004CAA7)       // Failed sanity check.  Byte order sanity test failed.

Once you've retrieved the GPSExifProperties object from either of the above two methods, you can
access the following exposed properties.

Note: If the value of a particular property is not set in the Exif data, then the property value
will be a zero-length string (for Strings) or Empty (for Variants).  In both cases, you can test
for presence of the property by using VBA code such as "If Len(Object.PropertyName) > 0 Then".

FilePath                   STRING,         full path to the file being parsed.

DateTimeOriginal           STRING,         format: "yyyy:mm:dd hh:nn:ss"

GPSVersionID               STRING,         format: "x.x.x.x" typically "2.1.0.0" or "2.2.0.0"

GPSLatitudeDecimal         VARIANT/DOUBLE, latitude in decimal degrees

GPSLongitudeDecimal        VARIANT/DOUBLE, longitude in decimal degrees

GPSAltitudeDecimal         VARIANT/DOUBLE, altitude in meters

GPSTimeStamp               VARIANT/DATE,   UTC time stamp

GPSSatellites              STRING,         Indicates the GPS satellites used (no specific format)

GPSStatus                  STRING,         Indicates GPS receiver status
                                           [
                                            "A" = Measurement In progress,
                                            "V" = Measurement is Interoperability
                                           ]

GPSMeasureMode             STRING,         Indicates the GPS measurement mode
                                           [
                                            "2" for 2D,
                                            "3" for 3D
                                           ]

GPSDOPDecimal              VARIANT/DOUBLE, Indicates the data degree of precision

GPSSpeedRef                STRING,         Indicates the unit used to express the GPS receiver speed of movement.
                                           [
                                            "K" = Kilometers/hour,
                                            "M" = Miles/hour,
                                            "N" = Knots
                                           ]

GPSSpeedDecimal            VARIANT/DOUBLE, Speed of the GPS receiver movement

GPSTrackRef                STRING,         Indicates the reference used for giving the direction of GPS receiver movement.
                                           [
                                            "T" = True direction,
                                            "M" = Magnetic direction
                                           ]

GPSTrackDecimal            VARIANT/DOUBLE, Direction of GPS receiver movement

GPSImgDirectionRef         STRING,         Indicates the reference used for the captured direction.
                                           [
                                            "T" = True direction,
                                            "M" = Magnetic direction
                                           ]

GPSImgDirectionDecimal     VARIANT/DOUBLE, Direction of the image when it was captured.

GPSMapDatum                STRING,         Indicates the geodetic survey data used by the GPS receiver

GPSDestLatitudeDecimal     VARIANT/DOUBLE, latitude of destination point in decimal degrees

GPSDestLongitudeDecimal    VARIANT/DOUBLE, longitude of destination point in decimal degrees

GPSDestBearingRef          STRING,         Indicates the reference used for giving the bearing to the destination point.
                                           [
                                            "T" = True direction,
                                            "M" = Magnetic direction
                                           ]

GPSDestBearingDecimal      VARIANT/DOUBLE, Bearing to the destination point

GPSDestDistanceRef         STRING,         Indicates the unit used to express the distance to the destination point.
                                           [
                                            "K" = Kilometers,
                                            "M" = Miles,
                                            "N" = Knots,
                                           ]

GPSDestDistanceDecimal     VARIANT/DOUBLE, Distance to the destination point

GPSProcessingMethod        STRING,         A character string recording the name of the method used for location finding.'

GPSAreaInformation         STRING,         A character string recording the name of the GPS area.'

GPSDateStamp               STRING,         format: "yyyy:mm:dd"'

GPSDifferentialCorrection  VARIANT/BOOL,   Indicates whether differential correction is applied to the GPS receiver.

Rate this article:  Your rating: PoorYour rating: Not so goodYour rating: AverageYour rating: GoodYour rating: Excellent


Have your say - comment on this article.

What did you think of 'Extracting GPS data from JPEG files'?


1.

Ian Higgins says...

11 Jul 2012

 
Thanks Wayne, the GPSExifReader class is a boon to all humankind (at least to those using Access). It has worked flawlessly for me and was very easy to implement.

2.

Tom says...

02 Oct 2013

 
Great piece of programming, easy to implant and after endless searching in the internet finally a piece of code that can be implanted directly in VBA without having to deal with VB

3.

Ilya says...

04 Feb 2014

 
Thank you very much!!!!!!!!

I thought that it was impossible to find, all day I've been surfing the internet. It works!!!! I'm trying to use your code in autocad.

Have your say...

Name
E-mail (e-mail address will be kept private)
Comments


Comments require approval before being displayed on this page (allow 24 hours).