
Most photos taken by smartphones today contain a lot of metadata, including Gps data. GPS data refers to the Latitude and Longitude coordinates of where the photo was taken.
When we get the GPS coordinates of the photo, we can even input it into Google maps and see the exact location. Just input [Longitude], [Latitude] in the search bar of Google maps, and we can immediately see the location.
If we just want to check the GPS coordinate of a single photo, it is very easy. The coordinates, along with much other metadata, are available in the properties of the image itself.

However, what if we have hundreds of photos and we need to extract the GPS coordinates?
Python solution
We would be using the GPSPhoto library which can be easily installed through pip.
The code below will generate the list of photos we want to extract GPS coordinates. It will get all photos ending with jpg in the specified folder.
pip install GPSPhoto
import os
os.chdir('C:Usersmy_personal_profileimage_folder')
image_list = os.listdir()
image_list = [a for a in image_list if a.endswith('jpg')]
print(image_list)
You may also need to install the dependencies of the library, such as exifread and piexif, which are also available to install through pip.
If we print image_list, we would then get the list of all .jpg images in the image_folder folder.

Once we have verified the list of image file names, we can then extract the GPS coordinates.
from GPSPhoto import gpsphoto
for a in image_list:
data = gpsphoto.getGPSData(os.getcwd() + f'{a}')
print(data)

Exciting use cases
While looking at places for a photoshoot, I recently browsed back old photos on my phone and found this beautiful photo.

I would love to go there again for a proper photoshoot. I knew that this is one of the pods in Sungei Buloh Wetlands Reserve. However, there are several similar pods like this in the park, albeit slightly different models and different sunlight effects. In an attempt to identify them, I was searching in Google for the name of the pods, e.g. Mudskipper pod, Kingfisher pod, Eagle Point pod, etc, and see if it matches. However, I couldn’t be so sure because the images found on Google were sometimes wrongly tagged by the users.
Instead of going to Google street view and exploring these places one by one (and in the park a lot of times there are areas not covered by Google street view), this solution works wonderfully. I just extracted the GPS coordinate from all the many photos I took at Sungei Buloh Wetlands Reserve and I was able to get the exact location. This helped me make a good photoshoot plan.

A caveat
If you are worried that photos you took and upload to social media or shared via messaging apps would reveal your location, fret not! Not all photos would contain such information. I have also checked the photos found on Google search, those uploaded by friends on Facebook, and even the photos I directly share on WhatsApp. They do not contain such information. If you share the raw file of the photo, then it is likely that the photo would contain the GPS coordinates.
Conclusion
Hope this article has helped you in automating the extraction of GPS coordinates from photos. If you want to extract other metadata from the photo, other libraries exist for this. However, if you just want to extract GPS data, this is by far the simplest method to do so.
Check out my other articles:
7 Data Visualization Best Practices Everyone Must Know
Deming’s 14 Management Principles Every Managers Should Know