a jpeg can have exif data associated with it, in the same file. This can store all kinds of things, but using a basic digital camera will typically have date, time, camera model, and photo exposure settings. It can also store info on image orientation, latitude, longitude, state, city, etc...
Most cameras do not fill this in automatically, as they have no way of knowing position. But if you geocode your images (by matching the photo timestamp to the timestamps in a log from a GPS device) there are various utilities that let you query city, state, etc based upon latitude and longitude. This is how these fields are generally populated. Of course, there are tools that let you populate the exif headers manually, but for large numbers of photos this can be a pain...