Click here to Skip to main content
15,122,251 members
Articles / Programming Languages / C#
Posted 7 Mar 2010


83 bookmarked

Exploring GoogleGears Wi-Fi Geo Locator Secrets

Rate me:
Please Sign up or sign in to vote.
4.93/5 (42 votes)
14 Apr 2010CPOL5 min read
This is a C# application that uses the Google Location service to retrieve location information using Wi-Fi towers.


I knew about Google Latitude from a friend when I bought my HTC mobile. I used it a few times before I updated my ROM to a cooked ROM that has no Google Latitude app installed. The story begins when I noticed by chance that my Google Latitude gadget on iGoogle reflected my location although I had not accessed Google Latitude from my mobile recently. I Googled for geo features of Google Gears and discovered that they are able to give you your location using Wi-Fi towers only. What follows is a discussion about Google Gears geo features and a proposal of how it might work. I developed a tool as a proof-of-concept of how can we use Wi-Fi geo location directly using a simple C# application.


The article is divided into two sections. The first section is an investigation and ideas about how Google can get geo location using only local Wi-Fi! The second part is the coding part, in which we make an application that uses Google services to get geo location.



First, try to connect your computer to a wired network - no Wi-Fi - and then try to find your location using Google Latitude. Google will give you "Unknown Location" as it will not be able to locate your location. Switch the very same computer to a Wi-Fi connection and use Google Latitude again. Now the result will be completely different - Google can give you accurate coordinates of your location. That means the location cannot be determined by the IP address only. Using IP, you can know the country, city, and regions in case you know from ISPs how they distribute their IPs geographically.

The second thing I heard about is that BBC has a service that gives you weather information based on your location that it gets from Google Gear. I decided to monitor HTTP traffic using a tool such as Fiddler. I was looking for:

  1. What data is retrieved from my PC in order to locate my location?
  2. How does BBC communicate with the Google location service via my PC?

The BBC weather site downloads JavaScript to my PC that locally calls Google Gears, and then Google calculates my location and sends it to the BBC website. The following figure shows this information. As we can see, Google Gears collects all Wi-Fi towers that can be detected from my PC in the following form: { mac_address , signal_strength, SSID}.


This data is sent in JSON format to and Google replies with my latitude, longitude, and even my own address. The above information that is sent to Google is good enough to roughly locate your position relative to these Wi-Fi towers, but to locate the absolute location, you need to know the absolute location of these Wi-Fi towers!! Again, it is not clear to me how Google knows such information. I made some more investigation and found that in case GSM data is available, this data is also sent together with the Wi-Fi information.

How does Google Gears Geo Location work?

From here, I will try to describe, based on the above info, how Google might use this information to give location information. In the case of GPS, data sent to Google contains:

  1. GPS data
  2. GSM towers
  3. Wi-Fi towers

In the case of a mobile that supports a GPS, it is enough to determine the GSM towers to have accurate info about location. This info is sent to Google as part of the request. But as we can see, this information already contains the geo location, so Google might do the following:

  1. Calculate you location [latitude and longitude].
  2. Use Wi-Fi data to calculate your relative position to each Wi-Fi.
  3. Calculate the absolute position of each Wi-Fi tower based on a and b:
    1. Mobile absolute location is already known.
    2. Wi-Fi relative location from the mobile is known.


Now, Google stores the mac_address and the SSID together with the absolute location in a geo database that is kept updated when possible.

In case you open your laptop and connect to Google Latitude, Google can determine your absolute location using the Wi-Fi towers only because it already knows, from other queries from you and different persons, the absolute location of the Wi-Fi towers. As we can see in the following figure, the blue person sends GPS, GSM towers info, and Wi-Fi towers info. Google calculates the Wi-Fi towers info. Now the green person can know his location by querying Google with Wi-Fi towers only.

This is not that easy. We need to think of many challenges such as similar Wi-Fi names, changing mac-addresses, Wi-Fi turning on/off etc.

Let's Make Our Application

The desktop application that I made here is a POC, and is pretty simple. It works in two steps:

  1. Get Wi-Fi data from PC.
  2. Send this info to Google and wait for response.

The first part is possible using a useful library to access Wi-Fi information from C#.

Get the Wi-Fi adapter:

Json = @"{ ""host"" : ""Test"", 
                ""radio_type"" : ""unknown"", 
                ""request_address"" : true, 
                ""version"" : ""1.1.0"", 
                ""wifi_towers"" : [ ";

WlanClient wLanClient = new NativeWifi.WlanClient(); // Get Wifi Interface
if (wLanClient.Interfaces.Length == 0)
    MessageBox.Show("No Wifi Interfaces found.");
Wlan.WlanBssEntry[] lstWlanBss = wLanClient.Interfaces[0].GetNetworkBssList(); 
if (lstWlanBss == null)
    MessageBox.Show("No networks has been detected.");

Enumerate the available Wi-Fi towers and concatenate the JSON string.

System.Text.StringBuilder SB = new StringBuilder();
foreach (var oWlan in lstWlanBss )
    ListViewItem lstItem = lstWifi.Items.Add(

    string MAC = ConvertToMAC(oWlan.dot11Bssid);
    SB.Append(@"{""mac_address"" :""");
    SB.Append(@", ""signal_strength"" :");
    SB.Append(@", ""ssid"" : """);
    SB.Append(System.Text.Encoding.UTF8.GetString(oWlan.dot11Ssid.SSID, 0, 
    SB.Append(@""" },");
Json += SB.ToString().Substring(0, SB.Length - 1); // copy all except last ","
Json += "]}";

textSent.Text = Json;

The second part is to form an HTTP request and parse the response.

HttpWebRequest request = 
request.ContentType = "application/json; charset=utf-8";
request.Accept = "application/json, text/javascript, */*";
request.Method = "POST";

using (StreamWriter writer = new StreamWriter(request.GetRequestStream()))
WebResponse response = request.GetResponse();
Stream stream = response.GetResponseStream();
string json = "";

using (StreamReader reader = new StreamReader(stream))
    while (!reader.EndOfStream)
        json += reader.ReadLine();

txtResponse.Text = json;

Points of Interest

If the Wi-Fi section is not working with you if you don't have Wi-Fi, you can still use the application by editing the request text to retrieve different locations.


The above Google technique is only a guess by me based on simple evidence and logic thinking. This document describes the analytical thinking and how I deduced this technique that could be partially or totally untrue.

Useful Links


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Mohammad Said Hefny
Egypt Egypt
No Biography provided

Comments and Discussions

Questiontime of measuring Pin
Member 127739543-Oct-16 11:21
MemberMember 127739543-Oct-16 11:21 
Bugbug fixed Pin
gfazzola5-Dec-15 3:53
Membergfazzola5-Dec-15 3:53 
QuestionTnanks Pin
gfazzola5-Dec-15 3:48
Membergfazzola5-Dec-15 3:48 
QuestionUnfortunately, it seems as if google doesn't return any requests anymore Pin
FredWah29-Nov-12 12:11
MemberFredWah29-Nov-12 12:11 
QuestionRe: Unfortunately, it seems as if google doesn't return any requests anymore Pin
Member 964160129-Nov-12 18:43
MemberMember 964160129-Nov-12 18:43 
AnswerRe: Unfortunately, it seems as if google doesn't return any requests anymore Pin
Mohammad Said Hefny29-Nov-12 19:14
MemberMohammad Said Hefny29-Nov-12 19:14 
GeneralRe: Unfortunately, it seems as if google doesn't return any requests anymore Pin
Member 964160130-Nov-12 1:23
MemberMember 964160130-Nov-12 1:23 
GeneralRe: Unfortunately, it seems as if google doesn't return any requests anymore Pin
FredWah30-Nov-12 3:04
MemberFredWah30-Nov-12 3:04 
QuestionNot works, please update application Pin
rafaelr.faria7-Nov-12 2:00
Memberrafaelr.faria7-Nov-12 2:00 
GeneralMy vote of 5 Pin
twphoenix17-Oct-12 18:34
Membertwphoenix17-Oct-12 18:34 
QuestionCan Wifi Signal be used to find distance of its adhoc clients? Pin
GPUToaster™14-Sep-12 1:50
MemberGPUToaster™14-Sep-12 1:50 
AnswerRe: Can Wifi Signal be used to find distance of its adhoc clients? Pin
Mohammad Said Hefny29-Nov-12 19:03
MemberMohammad Said Hefny29-Nov-12 19:03 
GeneralRe: Can Wifi Signal be used to find distance of its adhoc clients? Pin
GPUToaster™4-Dec-12 22:44
MemberGPUToaster™4-Dec-12 22:44 
But what if we could triangulate its coordinates with respect to the WIFI router and a reference router? I am not sure just for argument sake?

True Regards.

A drop of water breaks a rock not by brute force but by patience.
Questionhello Pin
ram vilas pawar9-Dec-11 8:19
Memberram vilas pawar9-Dec-11 8:19 
GeneralMy vote of 5 Pin
Sergio Andrés Gutiérrez Rojas26-Sep-11 19:27
MemberSergio Andrés Gutiérrez Rojas26-Sep-11 19:27 
GeneralWINXP sp3 not working... Pin
nacl1-May-11 10:17
Membernacl1-May-11 10:17 
GeneralRe: WINXP sp3 not working... Pin
Mohammad Said Hefny12-Apr-12 1:03
MemberMohammad Said Hefny12-Apr-12 1:03 
GeneralUrgent: ERROR:The type or namespace name 'var' could not be found (are you missing a using directive or an assembly reference?) Pin
noureddine6-Apr-11 1:04
Membernoureddine6-Apr-11 1:04 
GeneralRe: Urgent: ERROR:The type or namespace name 'var' could not be found (are you missing a using directive or an assembly reference?) Pin
Mohammad.Hefny29-Jul-12 16:08
MemberMohammad.Hefny29-Jul-12 16:08 
GeneralGoogle Andoid shows how can wifi together with GPS determine places...notice the wifi cancelled cell in the topic Pin
Mohammad Said Hefny9-Dec-10 8:58
MemberMohammad Said Hefny9-Dec-10 8:58 
Generalsome thoughts Pin
Spypan21-Aug-10 0:22
MemberSpypan21-Aug-10 0:22 
GeneralRe: some thoughts Pin
Mohammad Said Hefny29-Nov-12 19:04
MemberMohammad Said Hefny29-Nov-12 19:04 
GeneralVery informative article Pin
Jitendra Zaa14-Apr-10 23:34
MemberJitendra Zaa14-Apr-10 23:34 
GeneralExcellent! I just summary the useful links for WIFI Geolocation. [modified] Pin
dancefire23-Mar-10 0:01
Memberdancefire23-Mar-10 0:01 
GeneralRe: Excellent! I just summary the useful links for WIFI Geolocation. Pin
Mohammad Said Hefny31-Mar-10 7:31
MemberMohammad Said Hefny31-Mar-10 7:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.