How exactly does geolocation work in browsers
Determine the location in the browser using the HTML5 Geolocation API
All browsers that no longer date from the digital stone age (Internet Explorer 9, Firefox 3.5 and Google Chrome) are able to use the geolocation API officially provided by the W3C to provide information about the location of the User is located.
How is the location determined using the geolocation API?
The location determination via HTML5 is relatively complex and mature and goes through a number of steps to determine with increasing accuracy:
- IP address
- WiFi networks
- Radio signals (cellular network)
- GPS transmitter (only with 'enableHighAccuracy')
The determination of the location works very precisely if the user has a GPS transmitter in his device. Of course, this is practically never the case with stationary PCs; However, every common smartphone nowadays has a GPS module and can thus provide an exact position determination - also to the browser. Information from the WLAN and cellular network is also used if no GPS data is available. Only in the worst case does the browser access the IP address, which however can have an inaccuracy of 50-100km due to the use of dial-in nodes.
Determine current location with getCurrentPosition ()
Access to the Navigator object (window.navigator) is sufficient to initiate the determination of the position:
The "position" object has the following properties:
|double or||Degrees clockwise from north|
|double or||Meter / sec.|
Example of location determination with HTML5 geolocation
When loading this page, the browser asked you whether you would like to allow selfhtml5 to determine your location. This dialog is browser-dependent and (currently) looks like this in FireFox, for example:
Depending on whether you have given your consent to the location determination or not, your position or an error message will appear in the following box.
Your position data determined by the browser
And here is the code for the geolocation example
How accurate is position determination via geolocation?
As we have seen, geolocation API makes it easy to find your location. It gets a little more exciting when we have higher demands on the accuracy of the measurement data.
As can be seen in the table above, the position object already provides an accuracy, the “accuracy” in meters, which is intended to quantify the maximum possible deviation. The results of this attribute can be very different depending on the device used. In this context, it is also important whether the geolocation should be determined with a high degree of accuracy (enableHighAccuracy), as described in the next chapter.
The following are the typical accuracies of geolocation determination:
|Smartphone without GPS||20-80m|
|Smartphone with GPS||5-20m (with enableHighAccuracy)|
Location determination with high accuracy through "enableHighAccuracy"
If you want to determine a very precise location, you still need GPS according to the current state of the art. The useful chips are now built into all modern smartphones and are therefore basically an excellent choice for determining your location, if there were not some restrictions to be observed:
- GPS tracking is energy-intensive and significantly reduces battery life
- Positioning via GPS requires an initialization phase of up to 15 minutes if it has been a long time since you last used GPS before results are available. In everyday smartphone life, however, relatively current satellite data is often available and the measurement usually takes between 10 and 30 seconds.
- The user may have to agree to the exact location determination one more time, as there are separate rights in browsers as well as iOS and Android
If, despite these restrictions, it is sensible or necessary to determine the location via GPS, the use of the GPS module can be made by transferring the parameter enableHighAccuracy to be activated:
Problems with the HTML5 geolocation determination
The W3C stipulates that the location may only be determined with the express consent of the user. The browser providers have implemented this accordingly - this means that, depending on the browser, a warning message pops up or is inserted under the address line (sometimes difficult to see) and asks the user whether he would like the location data to be determined make sure to point out at the appropriate point that the service only works after acceptance of the location transfer.
- What is the Fran CrossFit Training
- Dying pigeons after mating
- What is a hindu jain temple
- When will the pain of love die
- How is ambition explained by evolutionary psychology?
- What is social security based on
- Should the UN have nuclear weapons
- How does rust form on metal under water?
- How to fix screeching brakes
- How do epoxy and fiberglass differ
- Why was the kindergarten for adults invented in 2017
- How can I clean filmy wooden floors
- Are you Japanese or Chinese
- The 240SX is a good first car
- When do you use the sport mode
- How to sell equipment
- What is Ranveer Singh's net worth
- Why have leopards become endangered species?
- What is the success of OPEC
- What's your best hack for creating online courses
- Take foreign language courses from DU Help
- What are free and paid blog posts
- Where do squirrels live
- How much do academic researchers earn