Sunday, December 4, 2011

How does Google Geolocation work ?

How does Google track us ?                    
The answer is two fold. First Google collects the user's IP address and surrounding WiFi Towers and their signals. But this activity has to be allowed by the user.
Second Google transports these data to a IP geolocation databases. Additionally also to a residential hotspot database. These geolocation services help to pinpoint the location of the user.


Details Please !                               
To see this entire procedure in action
1) Install HTTP Watch a freeware.
2) Now go to maps.google.com
3) Click on "Get Directions"
4) Start HTTP Watch and now start recording the activity.
5) In  Point A make sure you can see "My Location". If not then type "My Location"
6) In Point B enter some address nearby
7) Let the Google maps complete its activity. You might see "My Location" being calculated
    by a rotating circle.
8) Next Stop the trace.
9) Select the "POST data" TAB from the bottom and check for one of the POST messages from the Method Column.

You will see a POST message to www.google.com/loc/json
with the content  like this

(Content) {"version":"1.1.0","request_address":true,"access_token"2:16bytes:16bytes","wifi_towers":[{"mac_address":"xx-xx-xx-xx-xx-xx","ssid":"SUPERMAN","signal_strength":-45},
 {"mac_address":"xx-xx-xx-xx-xx-xx","ssid":"BATMAN","signal_strength":-85}
 {"mac_address":"xx-xx-xx-xx-xx-xx","ssid":"SPIDERMAN","signal_strength":-77}
 {"mac_address":"xx-xx-xx-xx-xx-xx","ssid":"IRONMAN","signal_strength":-71}}

For the same message click on Content and you shall see the result of the query.

{"location":{"latitude"XX.XX,"longitude":XX.XX,"address":{"country":"United States","country_code":"India","region":"MH","city":"Mumbai","street":"World's Longest Street","street_number":"","postal_code":"4007"},"accuracy":111.0}}

Here is the specification of this entire protocol.
http://code.google.com/apis/gears/geolocation_network_protocol.html

You can see the entire POST message has WiFi related data as clear text. But you cannot find an IP address ?
I wonder if the IP address is detected from the query to the server. It need not be communicated.
Access token is provided once to a user which can be used for subsequent requests.
A new Access Token is provided if the user clears the cache.

How does Google accumulate the geolocation data ?
Google seems to have their own geolocation service.
Also looking at the POST data format in the geolocation API spec at this link,
Smart Phones with google maps can send GEARS request with  Phone's Current GPS location+Surrounding Cell towers+Surrounding WiFi Towers. Thus helping to accumulate more data.

How does Google Maps get easy access to data like Surrounding WiFi Towers ?                 

On a desktop its the Browser that queries the OS for the WiFi Towers.
Firefox browser acquires the list of WiFi towers nearby your laptop which it sends to the google location service. And similarly Chrome and IE.


Mac
Gears uses a single API to retrieve wifi scan data, the Apple80211.h header taken from the iStumber project.
Linux
Gears used a support executables (iwlist / iwconfig) from the to perform scans, due to GPL linkage reasons.
Windows 7
has a native location API.

Reference: https://docs.google.com/View?id=dfbnm49n_0dpc7pxpx&pli=1


On a Smartphone the app google maps acquires the data and sends it to the Google Location Service.
Android
Following is the article for developers to get access to user's location with Android. Google maps  or any other application can use the classes mentioned in this article to acquire the user's details  like WiFi Towers etc.
Refrence: http://developer.android.com/guide/topics/location/obtaining-user-location.html