often
hit the questions about Geolocation in Web browsers. People are sometimes confused by its results. Eg. wondering why their computer returns a different data than the other computer in the same room, etc. explain in detail how it works in Firefox Geolocation. Perhaps then you can answer your questions. I will deal only with Firefox - the other browsers I've not examined in detail, but some of that can certainly be applied to them.
If you want a comprehensive look at issues, look at my lecture with geolocalisation would lose even Hansel and Gretel .
Let's start with the JavaScript code for geolocation geolocation
Use the website is quite easy. Just to call one function, namely: navigator.geolocation.getCurrentPosition (see upcoming W3C standard ).
And to try: full working example (note the top right panel, you have to confirm).
That's how it looks easy. But let's look at what exactly will happen since you allow your browser to identify the location to obtain the final coordinates. Yourself then you should be able to answer questions such as why Firefox sometimes returns the position precisely (in increments of 150 meters) and sometimes usable and has a scattering of many kilometers.
Step 1 The findings of geolocation data
If the viewer to determine your location, you must collect the information needed for geolocation. Such data are several. What is perhaps always available, your IP address (or public IP gateway through which you connect to the internet). By comparing the IP address of the relevant databases is possible to estimate your location. This is the worst figure Geolocation accuracy (dispersion units, tens, sometimes hundreds of miles - Prague has an IP address is located to the center of dispersion 140 km).
But better than nothing. The IP address is almost always correctly determine the user's country, the better if the city in which the user is located. (It's not perfect either. If as a user of the city and connected to the Internet through a VPN in city B, then in this way as the midway town of B.) Since the method is any better than Geolocation by IP address, the IP address only when nothing else is available. Otherwise ignored.
Does your computer Wi-Fi ? Then your position may be determined more accurately. If Wi-Fi to your computer turned on, Firefox will load all hotspots, which currently see (their names, MAC address and signal strength) and apply them to the geolocation (using up to a global database of Wi-Fi hotspots).
This option expires desktop Firefox. For mobile browsers in addition applicable even use the BTS in your area (it works on the same principle as the Wi-Fi with the difference that reaches beyond the BTS signal, thus Geolocation using the BTS will be less accurate than Geolocation using Wi-Fi). And finally there is the possibility using the GPS built into the phone.
We are counting on desktop Firefox, so we only know the IP address and Wi-Fi in the neighborhood.
Step 2 Queries Google Geolocation
I have indicated, that the mere knowledge of IP addresses, or Wi-Fi is not enough points, you need to compare them to a database containing the location of all (or not all, but a sufficient number of) IP addresses and Wi-Fi points.
Firefox to use Google's database. (The number of such databases, but Google is probably one of the biggest = best.) Google's compiled Geolocation API Network Protocol through which the Firefox (or your own applications, as they still show) to communicate with its databases.
in about: Firefox prefs Preferences found geo.wifi.uri key with the value https: / / www.google.com / loc / json.
This is the URL to the Firefox Geolocation API communicates with the Network Protocol. How does communication look like?
Let's say that my computer "sees" a Wi-Fi called "default" and address "00-0e-2e-7d-7d-0E". The request looks like this: {
Note that in addition to the protocol header with a version number contains only the Wi-Fi point, nowhere in it does not feature information about your IP address. There needs. Google to use an IP address from which his request arrives.
"Version", "1.1.0",
"wifi_towers": [{
"mac_address": "00-0e-2e-7d-7d-0E"
"signal_strength": -49,
"SSID: "default"
}]}
Note: If you would like communication between Google and eavesdrop on your browser and you have a problem with HTTPS, you can change geo.wifi.uri value of http://www.google.com/loc/json (notice the change log of HTTPS to HTTP). Just want to log the data that Firefox sent geolokačním protocol, the service proved to me http://www.postbin.org/ set geo.wifi.uri to generate postbin and see what Firefox sends. (After testing geo.wifi.uri return to its original value.)
to privacy: geolocation requirements contain cookies. This is because of privacy. You are currently logged on to Google, but Firefox Cookies logged on to https: / / www.google.com / loc / json just not send. Some object that if Google really wanted to, you can connect the user's identity using an IP address and watch it anyway. It certainly can.
On the other hand, filtering out cookies, Google did what it was simply impossible. Your IP address will not filter out (if we do it have not some third party would conduct anonymous IP addresses, and this hand, we wholeheartedly believe ...).
The user is assigned an identifier, however, that the browser for some time, holds. Google can monitor the movement of a particular user, that user will not be represented by a cookie (ie googlím your account, ie their identity), but randomly generated identifier. I assume that Google uses to monitor the construction and renovation of its global database of Wi-Fi points and BTS (geolocation when in fact both determined by your location, but at the same time and builds a database with Google - the wonderful solve engineering problems).
Summary: The geolocation therefore some reasonable privacy takes place, even though it is theoretically overcome by Google (if they want it, you will find you and that's it!).
Step 3 How Google determines the location
We ended up sending a request to the URL https: / / www.google.com / loc / json.
Google Answers as follows:
{"location": {
"Latitude": 50.1001961,
"longitude": 14.4228038,
"Accuracy": 150.0
}
access_token ":" 2: Ta5Y_rSUZbO4rpJD: _FXkzUcxD1OWG-YM "
} result we can see on the map . Visitors to the Prague meetings and Ruby Last Saturday certainly know that this is a well-known firm called Fractal. access_token item is ONEM said identifier is assigned by Google to you and who will bear the additional requirements of Firefox geolocation.
Note that using Wi-Fi can draw really well. Took one Wi-Fi, and we have our position in increments of 150 meters! So it really is. I have the same experience made a number of other places not only in Prague, Plzen and Brno. Geolocation using Wi-Fi is incredibly accurate.
The fractal is, in fact, 3-5 Wi-Fi points. The request will be sent to all Google, but he just one of them (does not matter which).
Exceptions: Even in cities there are places that Google has targeted precisely. The exceptions, but rarely come across and do not always last long. Google's database is samoopravující.
I watched a few poorly aimed points and in a few weeks or months to clarify their position. Similarly, it is when a Wi-Fi point moves (if someone moves to another town Bring Wi-Fi router), even in that case, the position eventually stabilize at a new location.
(The observant reader just discovered the way to easily track, which moved its neighbors. If you bring my Wi-Fi router can be over time to determine their new residence with an accuracy of 150 meters. And in virtually any part of the civilized Globe!)
If you get a new Wi-Fi router, then a few weeks and months we will get into the database. (If you wonder how, read what it means wardriving or warwalking .)
Is your Wi-Fi router in Google's database?
It easy to see. I prepared to simple tool (it is a simple application that directly asks Google Geolocation database). Just a text box, enter the MAC address of your Wi-Fi format, which uses the Geolocation protocol, as follows:
{"version", "1.1.0", "wifi_towers":
[{"mac_address": "00-0e-2e-7d-7d- 0e "}]} and submit. In 90% of cases, see your exact location (150m). However, if you this file, you are one of the few cases that are not in Google's database. Then Google uses the IP address (because my application is hosted at Google's IP address located in the sort of town in America).
If you have a new Wi-Fi router that Google has not yet knows, or if you have the solitude that the Google database still does not know, deliberately observe how long it will take to discover the database.
Now you need to know everything about the Geolocation. Or not? Let's have some facts.
Wi-Fi base
If you are in one room, two computers and one of them has turned on Wi-Fi, so that with Wi-Fi should you have to locate exactly (those at 150m). Try it at maps.google.com (blue button top left) or JavaScript to my demo the beginning of the article. A computer without Wi-Fi quite usable, and conversely you probably fit somewhere in the center of the nearest big city. You can try it on the same computer on or off Wi-Fi (sometimes need to restart Firefox in the meantime, changes to take effect).
What if Google sends inconsistent data?
I do during my experiments I tried 8-) The standard requirement for Firefox sends a list of Wi-Fi points in the neighborhood, Google will find their position in the database and then provides them user location (probably as the center points of all Wi-Fi access - at the moment ignores the signal and takes into account only the position of points).
What if you could get a claim which would also include Wi-Fi points in Prague and Brno? What to do? Stupid is not. He knows that such a large Wi-Fi signal does not. Decides, according to the individual points. If you request him to send one point from one of Prague and Brno, not by what they catch and Wi-Fi geolocation to apply (it still remains an IP address, which may touch).
If I sent from Prague 1 point and 2 points in Brno, then the point of Prague is considered as invalid, and Google uses geolocation to those two points in Brno (the same logic that works even when the higher number of points).
Note that we have just shown a mechanism by which Google can use to samoopravování its database. If, in fact even with its Wi-Fi router moves from Prague to Brno, so she comes exactly the above situation. Geolocation, and I run my computer Brno probably see several Wi-Fi points and one (my) in Prague. If such a request repeated often enough, it could be my router Prague considered moving to Brno and its position in the DB would update the.
are speculation, Google publicly specified what exactly keeps its database. Which probably never do, because otherwise we could perfectly well go gaga selected requirements and a database scatter it.
Conclusion
It is all from me. The more I examine this mechanism, the more I liked the way it is designed. And finally I have a small request. If you've ever studied, Geolocation how it works in other browsers, let me know (you and me, whether the database is also used Google or another).
At the very end thanks to David Majdi , Paul cricket and Maruška Graph who have assisted me in testing Geolocation in Prague and other cities.