コード例 #1
0
        /// <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(CellTower tower)
        {
            GeoLocation result = GeoLocation.Empty;

            try
            {
                // Translate cell tower data into http post parameter data
                byte[] formData = GetFormPostData(tower.TowerId,
                    tower.MobileCountryCode,
                    tower.MobileNetworkCode,
                    tower.LocationAreaCode);

                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();

                result = ReadResponse((HttpWebResponse)request.GetResponse());
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            return result;
        }
コード例 #2
0
        /// <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(CellTower tower)
        {
            GeoLocation result = GeoLocation.Empty;

            try
            {
                // Translate cell tower data into http post parameter data
                byte[] formData = GetFormPostData(tower.TowerId,
                                                  tower.MobileCountryCode,
                                                  tower.MobileNetworkCode,
                                                  tower.LocationAreaCode);

                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();

                result = ReadResponse((HttpWebResponse)request.GetResponse());
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            return(result);
        }
コード例 #3
0
        private void GetLocation(string cellId, string txt)
        {
            GeoLocation geoLocation = null;

            if (null != m_Storage)
            {
                DataRow row = m_Storage.GetCellByID(cellId);
                if (null != row)
                {
                    geoLocation = new GeoLocation {
                        Latitude  = Convert.ToDouble(row["Lat"].ToString().Replace('.', ',')),
                        Longitude = Convert.ToDouble(row["Lon"].ToString().Replace('.', ','))
                    };
                }
            }

            if (null == geoLocation)
            {
                // [0] - CID
                // [1] - LAC
                // [2] – MCC
                // [3] - Time

                /*---Arguments for GetLatLng(MCC MNC LAC CID)
                 * string[] args = {
                 *  cellidFields[2], // MCC
                 *  "0",             // MNC – don’t need it here
                 *  cellidFields[1], // LAC
                 *  cellidFields[0]  // CID
                 * };
                 */

                string[] cellidFields = txt.Split('-');

                CellTower cellTower    = null;
                bool      loadLocation = true;

                try
                {
                    cellTower = new CellTower
                    {
                        LocationAreaCode  = int.Parse(cellidFields[1]),
                        MobileCountryCode = int.Parse(cellidFields[2]),
                        MobileNetworkCode = 0,
                        TowerId           = int.Parse(cellidFields[0])
                    };
                }
                catch (Exception ex)
                {
                    loadLocation = false;
                }

                if (loadLocation)
                {
                    geoLocation = GoogleMapsCellService.GetLocation(cellTower);

                    if (null != m_Storage && geoLocation.IsValid)
                    {
                        m_Storage.InsertCellId(cellId, geoLocation.Latitude.ToString().Replace(',', '.'), geoLocation.Longitude.ToString().Replace(',', '.'));
                    }

                    Logger.Log("GetLocation - celltower id:{0} retreived from Service", cellTower.TowerId);
                }
                else
                {
                    geoLocation = GeoLocation.Empty;
                }
            }

            GeoLocation = geoLocation;
        }