Esempio n. 1
0
        public CellTower getTowerInfo()
        {
            IntPtr radioInterfaceLayerHandle = IntPtr.Zero;
            IntPtr radioResponseHandle       = IntPtr.Zero;

            // Initialize the radio layer with a result callback parameter.
            radioResponseHandle = RIL_Initialize(1, new RILRESULTCALLBACK(CellDataCallback),
                                                 null, 0, 0, out radioInterfaceLayerHandle);

            // The initialize API call will always return 0 if initialization is successful.
            if (radioResponseHandle != IntPtr.Zero)
            {
                return(null);
            }

            // Query for the current tower data.
            radioResponseHandle = RIL_GetCellTowerInfo(radioInterfaceLayerHandle);

            // Wait for cell tower info to be returned since RIL_GetCellTowerInfo invokes the
            // callback method asynchronously.
            waithandle.WaitOne();

            // Release the RIL handle
            RIL_Deinitialize(radioInterfaceLayerHandle);

            // Convert the raw tower data structure data into a CellTower object
            CellTower ct = new CellTower();

            ct.setTowerId(Convert.ToInt32(_towerDetails.dwCellID));
            ct.setLocationAreaCode(Convert.ToInt32(_towerDetails.dwLocationAreaCode));
            ct.setMobileCountryCode(Convert.ToInt32(_towerDetails.dwMobileCountryCode));
            ct.setMobileNetworkCode(Convert.ToInt32(_towerDetails.dwMobileNetworkCode));

            return(ct);
        }
Esempio n. 2
0
        public string getCoords(CellTower ct)
        {
            try
            {
                String         url = "http://www.google.com/glm/mmap";
                HttpWebRequest req = (HttpWebRequest)WebRequest.Create(new Uri(url));
                req.Method = "POST";

                byte[] pd = PostData(ct.getMobileCountryCode(), ct.getMobileNetworkCode(), ct.getLocationAreaCode(), ct.getTowerId(), false);

                req.ContentLength = pd.Length;
                req.ContentType   = "application/binary";
                Stream outputStream = req.GetRequestStream();
                outputStream.Write(pd, 0, pd.Length);
                outputStream.Close();

                HttpWebResponse res            = (HttpWebResponse)req.GetResponse();
                byte[]          ps             = new byte[res.ContentLength];
                int             totalBytesRead = 0;
                while (totalBytesRead < ps.Length)
                {
                    totalBytesRead += res.GetResponseStream().Read(ps, totalBytesRead, ps.Length - totalBytesRead);
                }

                if (res.StatusCode == HttpStatusCode.OK)
                {
                    short opcode1 = (short)(ps[0] << 8 | ps[1]);
                    byte  opcode2 = ps[2];
                    System.Diagnostics.Debug.Assert(opcode1 == 0x0e);
                    System.Diagnostics.Debug.Assert(opcode2 == 0x1b);
                    int ret_code = (int)((ps[3] << 24) | (ps[4] << 16) | (ps[5] << 8) | (ps[6]));

                    if (ret_code == 0)
                    {
                        double tlat = ((double)((ps[7] << 24) | (ps[8] << 16) | (ps[9] << 8) | (ps[10]))) / 1000000;
                        double tlon = ((double)((ps[11] << 24) | (ps[12] << 16) | (ps[13] << 8) | (ps[14]))) / 1000000;
                        lat = tlat;
                        lng = tlon;
                        return(tlat + "," + tlon);
                    }
                    else
                    {
                        return(null);
                    }
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception)
            {
                return(null);
            }
        }
Esempio n. 3
0
        private void MapTest_Load(object sender, EventArgs e)
        {
            tbDest.Text          = "Enter Destination";
            tbLoc.Text           = "Enter Location";
            pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
            p          = new Point();
            currMap    = new Mapping.Map();
            currMarker = new Mapping.Marker();
            mu         = new Mapping.MapUtils();
            gu         = new Mapping.GeoUtils();
            g          = new Mapping.Geo();
            //check phone radio is on.
            if (SystemState.PhoneRadioOff == false)
            {
                Cell.CellUtils cu = new Cell.CellUtils();
                Cell.CellTower ct = cu.getTowerInfo();
                g.setLatLng(cu.getCoords(ct));
                g.setLat(cu.getLat());
                g.setLng(cu.getLng());
                currCentre = gu.getGeoLocation(g);
                currMarker = new Mapping.Marker(1, "red", "S", currCentre.getCoords());
                //update location textbox
                tbLoc.Text = currCentre.getDisplay_address();
            }
            else
            {
                g.setAddress("ANU");
                currCentre = gu.getLocation(g);
            }

            //initialize map settings
            startLoc = new Mapping.Location();
            destLoc  = new Mapping.Location();


            currMap.setMapType("rmap");
            currMap.setCenter(currCentre.getCoords());
            currMap.setSensor("false");
            currMap.setSize(480, 300);
            currMap.setZoom(zoom.ToString());
            //currMarker = new Mapping.Marker(1, "red", "S", currCentre.getCoords());
            currMap.clearMarkers();
            currMap.setMarkers(currMarker.toString());
            pictureBox1.Image = mu.getMapImage(mu.generateMap(currMap));

            //add start location
            startLoc = new Mapping.Location();
            startLoc.setReady(1);
            startLoc.setLat(currCentre.getLat());
            startLoc.setLng(currCentre.getLng());
            startLoc.setCoords(currCentre.getCoords());

            //tbLoc.Text = currCentre.getDisplay_address();
        }
Esempio n. 4
0
        private void miGetCellLoc_Click(object sender, EventArgs e)
        {
            p          = new Point();
            currMap    = new Mapping.Map();
            currMarker = new Mapping.Marker();
            mu         = new Mapping.MapUtils();
            gu         = new Mapping.GeoUtils();
            g          = new Mapping.Geo();

            Cell.CellUtils cu = new Cell.CellUtils();
            Cell.CellTower ct = cu.getTowerInfo();
            g.setLatLng(cu.getCoords(ct));
            g.setLat(cu.getLat());
            g.setLng(cu.getLng());
            currCentre = gu.getGeoLocation(g);

            //update start location object
            startLoc.setLat(currCentre.getLat());
            startLoc.setLng(currCentre.getLng());
            startLoc.setCoords(currCentre.getCoords());
            startLoc.setDisplay_address(currCentre.getDisplay_address());
            startLoc.setReady(1);

            currMap.setMapType("hyb");
            currMap.setCenter(currCentre.getCoords());
            currMap.setSensor("false");
            currMap.setSize(480, 300);
            currMap.setZoom(zoom.ToString());
            currMap.clearMarkers();
            currMarker = new Mapping.Marker(1, "red", "S", startLoc.getCoords());

            if (destLoc.getReady() == 1)
            {
                currMarker = new Mapping.Marker(1, "yellow", "D", destLoc.getCoords());
            }

            currMap.setMarkers(currMarker.toString());
            pictureBox1.Image = mu.getMapImage(mu.generateMap(currMap));
            pictureBox1.Refresh();

            //update location textbox
            tbLoc.Text = startLoc.getDisplay_address();
        }