/// <summary>
        /// Gets the current latitude and longitude based on cell tower data.
        /// </summary>
        /// <param name="cellTowerId">The cell tower id.</param>
        /// <param name="mobileCountryCode">The mobile country code.</param>
        /// <param name="mobileNetworkCode">The mobile network code.</param>
        /// <param name="locationAreaCode">The location area code.</param>
        /// <returns></returns>
        public static GeoLocation GetLocation(RILCELLTOWERINFO t)
        {
            try
            {
                // Translate cell tower data into http post parameter data
                byte[] formData = GetFormPostData((int)t.dwCellID,
                    (int)t.dwMobileCountryCode,
                    (int)t.dwMobileNetworkCode,
                    (int)t.dwLocationAreaCode);

                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri(Google_Mobile_Service_Uri));
                request.Method = "POST";

                request.ContentLength = formData.Length;
                request.ContentType = "application/binary";
                Stream outputStream = request.GetRequestStream();

                // Write the cell data to the http stream
                outputStream.Write(formData, 0, formData.Length);
                outputStream.Close();

                HttpWebResponse response = (HttpWebResponse)request.GetResponse();

                return ReadResponse(response);
            }
            catch
            { }

            return GeoLocation.Empty;
        }
Esempio n. 2
0
        /*
         * Uses RIL to get CellID from the phone.
         */
        public static RILCELLTOWERINFO GetCellTowerInfo()
        {
            // initialise handles
            IntPtr hRil = IntPtr.Zero;
            IntPtr hRes = IntPtr.Zero;

            // initialise result

            CellTowerInfo = null;

            // initialise RIL
            hRes = RIL_Initialize(1,                                        // RIL port 1
                                  new RILRESULTCALLBACK(rilResultCallback), // function to call with result
                                  null,                                     // function to call with notify
                                  0,                                        // classes of notification to enable
                                  0,                                        // RIL parameters
                                  out hRil);                                // RIL handle returned

            if (hRes != IntPtr.Zero)
            {
                throw new Exception("Failed to initialize RIL");
            }

            // initialised successfully

            // use RIL to get cell tower info with the RIL handle just created
            hRes = RIL_GetCellTowerInfo(hRil);

            // wait for cell tower info to be returned
            waithandle.WaitOne();

            // finished - release the RIL handle
            RIL_Deinitialize(hRil);

            // return the result from GetCellTowerInfo
            // return celltowerinfo;

            return CellTowerInfo;
        }
        public static Coordinates GetLocation(RILCELLTOWERINFO t)
        {
            Coordinates coord = new Coordinates();
            try
            {
                string apiCall = OpenCellID_Service_Uri +
                    "&mnc=" + t.dwMobileNetworkCode +
                    "&mcc=" + t.dwMobileCountryCode +
                    "&lac=" + t.dwLocationAreaCode +
                    "&cellid=" + t.dwCellID;

                XmlDocument doc = new XmlDocument();
                doc.Load(apiCall);

                //EXAMPLE:
                // <cell mnc="99" lac="0" lat="50.5715642160311" nbSamples="57" range="6000" lon="25.2897075399231" cellId="29513" mcc="250"/>
                XmlNode rspNode = doc.SelectSingleNode("rsp");
                string status = rspNode.Attributes["stat"].Value;
                status.ToLower();

                if (status == "ok")
                {
                        XmlNode cellNode = rspNode.SelectSingleNode("cell");
                        int samples = int.Parse(cellNode.Attributes["nbSamples"].Value);

                        if (samples>0)
                        {
                            coord.Latitude = double.Parse(cellNode.Attributes["lat"].Value);
                            coord.Longitude = double.Parse(cellNode.Attributes["lon"].Value);
                            coord.Precision = double.Parse(cellNode.Attributes["range"].Value);
                        }
                }
            }
            catch
            { }
            return coord;
        }
Esempio n. 4
0
        public static void rilResultCallback(uint dwCode,
            IntPtr hrCmdID,
            IntPtr lpData,
            uint cbData,
            uint dwParam)
        {
            // create empty structure to store cell tower info in
            RILCELLTOWERINFO rilCellTowerInfo = new RILCELLTOWERINFO();

            // copy result returned from RIL into structure
            Marshal.PtrToStructure(lpData, rilCellTowerInfo);

            // get the bits out of the RIL cell tower response that we want
            CellTowerInfo = rilCellTowerInfo;

            // notify caller function that we have a result
            waithandle.Set();
        }