Getting geo-location from an ip address is only one of the ways to locate a machine (in our case, a phone, laptop or a desktop that has the browser on it). HTML5 provides a geo location api that can locate itself using any or combination of the following methods:
You can check how Firefox does it here: Firefox Geolocation. As a privacy feature, browsers do not track geo location all the time. When a user visits a location aware website, the website would ask for location information and the browser only shares it if the user has approved the request. As of Chrome v50.0, the geolocation feature only works on SSL enabled websites.
In IP Location method, we simply look up the IP address against the IP to location databases.
IP geolocation accuracy depends on the database used. That being said, it is quite accurate in locating the country, city and the postalcode (zipcode in the US).
HTML5 geolocation is often more accurate. In some cases it can locate your device withing a few metres. However, it all depends on the signal avaibility and the device you are using.