新聞中心

        EEPW首頁 > 汽車電子 > 設計應用 > 基于Android的位置實時監控系統的設計與實現

        基于Android的位置實時監控系統的設計與實現

        作者:張維文 孫耀杰 李利娟 時間:2015-04-23 來源:電子產品世界 收藏

          2.3 程序實現

        本文引用地址:http://www.104case.com/article/273085.htm

          一是定位功能的實現。充分利用智能手機內置定位模塊,基于Eclipse開發平臺通過程序的調用,實現定位功能,手機運行結果如圖4所示。其實現代碼如下:

          /**
          * 將獲得的位置信息顯示出來
          * @param location
          */
          private void setLocation(Location location){
          if (location != null) {
          String latitudeStr = Double.toString(location.getLatitude());//經度
          String longitudeStr = Double.toString(location.getLongitude());//緯度
          String altitudeStr = Double.toString(location.getAltitude());//海拔
          // 獲取當前時間
          SimpleDateFormat sDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss",Locale.CHINA);
          String dateStr = sDateFormat.format(new java.util.Date());
          gpsTime.setText(dateStr);
          if (latitudeStr != null && !latitudeStr.equals("")) {
          latitude.setText(latitudeStr);
          }
          if (longitudeStr != null && !longitudeStr.equals("")) {
          longitude.setText(longitudeStr);
          }
          if (altitudeStr != null && !altitudeStr.equals("")) {
          altitude.setText(altitudeStr);
          }
          } else {
          Log.v("location", "location為空");
          }
          }

          二是經緯度信息發送功能的實現。根據事先設置好的監控端手機號碼,按照發送頻率(時間間隔),將經緯度發送到監控端。其實現代碼如下:

          /**
          * 發送短信
          * @param smsContent 短信內容
          */
          private void sendSMS(String smsContent){
          //獲取短信管理器
          SmsManager smsManager = SmsManager.getDefault();
          //拆分短信內容
          List divideContents = smsManager.divideMessage(smsContent);
          if (curPhoneNum == null || curPhoneNum.equals("")) {
          new AlertDialog.Builder(MainActivity.this).setTitle("警告").setMessage("您還未設置目標電話號碼").create().show();
          return;
          }
          //發送短信
          for (String text : divideContents) {
          smsManager.sendTextMessage(curPhoneNum, null, text, null, null);
          }
          }



        評論


        相關推薦

        技術專區

        關閉
        主站蜘蛛池模板: 亳州市| 临泉县| 杭锦后旗| 普安县| 栾城县| 祁门县| 丹巴县| 克山县| 南乐县| 江川县| 吉林省| 乐至县| 碌曲县| 商洛市| 泰宁县| 开鲁县| 四平市| 突泉县| 五台县| 资阳市| 泰兴市| 梨树县| 临泽县| 望城县| 桐庐县| 轮台县| 谷城县| 花莲县| 莲花县| 陆川县| 麻阳| 集安市| 汨罗市| 达尔| 衡东县| 平乐县| 衡阳市| 封开县| 芷江| 皮山县| 肃南|