public static Coordinates GetCurrentPosition()
        {
            /*
             * zona de lisboa
             * Cell:12664 mcc:268 mnc:1 lac:8  OK
             * zona do porto
             * Cell:4661727 mcc:268 mnc:3 lac:51000 OK
             * cidade de madrid
             * Cell:10487683 mcc:214 mnc:3 lac:21601    OK
             * mexico
             * Cell:50243 mcc:310 mnc:100 lac:5 OK
             *
             * CellTowerInfo.dwCellID = 123365432;      ERROR
             * CellTowerInfo.dwLocationAreaCode = 124654321;
             * CellTowerInfo.dwMobileCountryCode = 310;
             * CellTowerInfo.dwMobileNetworkCode = 100;
             *
             * CellTowerInfo.dwCellID = 123365432;       ERROR
             * CellTowerInfo.dwLocationAreaCode = 3;
             * CellTowerInfo.dwMobileCountryCode = 543214;
             * CellTowerInfo.dwMobileNetworkCode = 100;
             *
             * CellTowerInfo.dwCellID = 123365432;
             * CellTowerInfo.dwLocationAreaCode = 3;
             * CellTowerInfo.dwMobileCountryCode = 108;
             * CellTowerInfo.dwMobileNetworkCode = 12765433;
             */

            RILCELLTOWERINFO CellTowerInfo = CellData.GetCellTowerInfo();

            Coordinates location = OpenCellIDCellService.GetLocation(CellTowerInfo);

            return(location);
        }
Example #2
0
        private static void rilResultCallback(uint dwCode,
                                              IntPtr hrCmdID,
                                              IntPtr lpData,
                                              uint cbData,
                                              uint dwParam)
        {
            try
            {
                Debug.WriteLine("rilResultCallback");
                // create empty structure to store cell tower info in
                RILCELLTOWERINFO rilCellTowerInfo = new RILCELLTOWERINFO();

                // copy result returned from RIL into structure
                Marshal.PtrToStructure(lpData, rilCellTowerInfo);
                Debug.WriteLine("struct recieved");

                // get the bits out of the RIL cell tower response that we want
                Debug.WriteLine("CellId: " + rilCellTowerInfo.dwCellID.ToString());
                Debug.WriteLine("AreaCode: " + rilCellTowerInfo.dwLocationAreaCode.ToString());
                Debug.WriteLine("CountryCode: " + rilCellTowerInfo.dwMobileCountryCode.ToString());
                Debug.WriteLine("NetworkCode: " + rilCellTowerInfo.dwMobileNetworkCode.ToString());
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Exception: " + ex.Message);
            }
            // notify caller function that we have a result
            waithandle.Set();
        }
        /// <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);
        }
Example #4
0
        public static void CellDataCallback(uint dwCode, IntPtr hrCmdID, IntPtr lpData, uint cbData, uint dwParam)
        {
            // Refresh the current tower details
            _towerDetails = new RILCELLTOWERINFO();

            // Copy result returned from RIL into structure
            Marshal.PtrToStructure(lpData, _towerDetails);

            // notify caller function that we have a result
            waithandle.Set();
        }
Example #5
0
        public static void CellDataCallback(uint dwCode, IntPtr hrCmdID, IntPtr lpData, uint cbData, uint dwParam)
        {
            // Refresh the current tower details
            _towerDetails = new RILCELLTOWERINFO();

            // Copy result returned from RIL into structure
            Marshal.PtrToStructure(lpData, _towerDetails);

            // notify caller function that we have a result
            waithandle.Set();
        }
Example #6
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();
        }
Example #7
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.CellID = rilCellTowerInfo.dwCellID;
            celltowerinfo.LAC = rilCellTowerInfo.dwLocationAreaCode;
            celltowerinfo.MCC = rilCellTowerInfo.dwMobileCountryCode;

            // notify caller function that we have a result
            waithandle.Set();
        }
Example #8
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);
        }
Example #9
0
        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);
        }
Example #10
0
        private 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

            int cid = Convert.ToInt32(rilCellTowerInfo.dwCellID);
            int bid = Convert.ToInt32(rilCellTowerInfo.dwBaseStationID);

            if (cid != CellId || bid != BaseStationId)
            {
                CellId        = cid;
                BaseStationId = bid;

                AreaCode      = Convert.ToInt32(rilCellTowerInfo.dwLocationAreaCode);
                CountryCode   = Convert.ToInt32(rilCellTowerInfo.dwMobileCountryCode);
                NetworkCode   = Convert.ToInt32(rilCellTowerInfo.dwMobileNetworkCode);
                TimingAdvance = Convert.ToInt32(rilCellTowerInfo.dwTimingAdvance);

                idChanged = true;
            }
            else
            {
                idChanged = false;
            }
            // notify caller function that we have a result
            waithandle.Set();
        }
Example #11
0
 public RILPositionProvider()
 {
     rilCellTowerInfo = new RILCELLTOWERINFO();
 }