public Location GetLocation() { WlanClient.WlanClient client = new WlanClient.WlanClient(); List<WifiAccessPoint> wifiAccessPoints = new List<WifiAccessPoint>(); foreach (WlanClient.WlanClient.WlanInterface wlanInterface in client.Interfaces) { Wlan.WlanBssEntry[] bssList = wlanInterface.GetNetworkBssList(); foreach (Wlan.WlanBssEntry bss in bssList) { WifiAccessPoint accessPoint = new WifiAccessPoint(); accessPoint.macAddress = ByteArrayToMacAddress(bss.dot11Bssid); wifiAccessPoints.Add(accessPoint); } } LocationRequest locationRequest = new LocationRequest(); locationRequest.wifiAccessPoints = wifiAccessPoints.ToArray(); string requestJson = JsonConvert.SerializeObject(locationRequest); byte[] requestBytes = GetBytes(requestJson); string url = "https://www.googleapis.com/geolocation/v1/geolocate"; HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url); webRequest.Method = "POST"; webRequest.ContentType = "application/json"; webRequest.Accept = "*/*"; webRequest.UserAgent = Program.APP_USER_AGENT; webRequest.ContentLength = requestBytes.Length; Stream requestStream = webRequest.GetRequestStream(); requestStream.Write(requestBytes, 0, requestBytes.Length); requestStream.Close(); WebResponse response = webRequest.GetResponse(); Stream responseStream = response.GetResponseStream(); StreamReader responseStreamReader = new StreamReader(responseStream); string responseJson = responseStreamReader.ReadToEnd(); responseStreamReader.Close(); responseStream.Close(); return JsonConvert.DeserializeObject<LocationResponse>(responseJson).location; }
internal WlanInterface(WlanClient client, Wlan.WlanInterfaceInfo info) { this.client = client; this.info = info; }