Our first go-to place to get the information is from the browser.
The location is given to the browser by Google, which utilises a variety of methods to determine the location. These methods are based on the WiFi hot-points the device sees.
Google learns this either from mobile devices that have geolocation enabled and are seeing WiFi hotspots or through the Google mapping cars that drive around hovering up WiFi hotspots and matching them to GPS data in the car.
Sometimes Google is unable to provide geolocation data to the browser. When that happens, we rely on using IP addresses and tapping databases provided by ISPs.
This information is often less accurate and downright incorrect depending on the ISP and their motive for publishing that data, however, in the absence of other data it is the best that can be got (and in most cases, it is pretty OK).