When taking a picture with a camera phone or a modern digital camera the image contains some additional meta data like what camera was used and the camera settings and if the user allows it a the GPS location of where the image was taken. This information in then stored along with the image and can be retrieved later.
Getting a position won't work if 1) the user disabled saving location on the image, 2) the image has been uploaded/downloaded from a image storing service like Facebook or Instagram, that strips the image of location information.