User:Suyash.dwivedi/userscripts/AutoAddLocationEXIF

Wikidata Location Button
AutoAddLocationEXIF is a powerful user script that extracts GPS coordinates directly from a file's metadata (EXIF data) and inserts the corresponding
| Camera location | | View all coordinates using: OpenStreetMap |
|---|
template. This tool is specifically helpful for images that contain embedded location data that hasn't yet been added to the wikitext.
Installation
To install this script, add the following line to your common.js page:
// Auto-Add Location Tag from EXIF Data mw.loader.load('https://commons.wikimedia.org/wiki/User:Suyash.dwivedi/userscripts/AutoAddLocationEXIF.js?action=raw&ctype=text/javascript');
How to use
- Navigate to a File: page (JPG, JPEG, TIFF, HEIF, or WebP).
- The script automatically scans the file's EXIF metadata upon loading.
- If valid GPS coordinates are found and no location template currently exists on the page, a blue button labeled Add location tag from EXIF data will appear at the top of the content area.
Click the button to:
- Extract the precise Latitude and Longitude.
- Clean up any redundant placeholders like

This image contains geographic location information in its Exif meta data. Users can then browse this category and insert a {{Location}} template into this image description page. If it could be geotagged but location in EXIF is faulty or wrong, remove this template and add {{GPS EXIF ambiguous}}. If it could be geotagged but that should never be done, remove this template and add {{Location withheld}}.
.
Smartly insert the
Camera location 
View all coordinates using: OpenStreetMap 
- template immediately after the
Description
Source
Author
block (or at the bottom if the template isn't found).
- The page will reload automatically once the edit is saved.
Features
- Metadata Extraction: Utilizes the
exif-jslibrary to read raw GPS tags from the image file.
- Smart Placement: Uses a bracket-matching algorithm to find the end of the
Description
Source
Author
template for clean wikitext placement.
- Format Support: Works with standard photographic formats including JPG, TIFF, and modern formats like HEIF and WebP.
- Conflict Prevention: The button only appears if the page does not already contain a location, camera location, or location dec template.
- Zero-Coordinate Filter: Automatically ignores invalid "0,0" coordinates often found in corrupted metadata.