What you need to know:
Digital cameras not only capture an image but also many additional data points about the image (called “EXIF data”) including: data/time, name/size of file, device, image resolution, among other metadata (data about data) which is attached to the image file.
Importantly, another data point the EXIF may contain is the location of where the photo was taken in the form of GPS coordinates. Smartphones capture this data by default and many DSLR and mirrorless cameras do as well if they have access to a GPS network.
Generally, if you share photos directly to others via email or text, the EXIF data will travel with it. If you post the images online, the details vary by site, where some will automatically remove the data before it’s shared, while others keep it on by default.
Most social media networks will strip the data before the image is shared to others, but will capture that data internally. Which they can then use for advertising purposes and/or potentially share with third parties.