2012-04-11 99 views
1

我正在研究一個處理谷歌地圖和GPS的Android應用。它的接近警報應用程序顯示地圖接受來自用戶的觸摸併爲該位置設置警報。我已經添加了一個EditText來接受用戶喜歡被通知多遠。但無論用戶輸入什麼內容,該應用都會將該值視爲2公里。是因爲它使用手機信息塔而不是GPS嗎?如果有任何教程可以幫助我開發應用程序,請分享它。當用戶在地圖上選擇一個位置時,會顯示一個新的屏幕讓用戶輸入通知距離。但是,當應用從地圖屏幕轉到用戶輸入屏幕時,GPS圖標會消失。可能是什麼問題呢?這是處理鬧鐘設置的部分。當Android應用切換到新屏幕時GPS連接丟失

mSetAlarm.setOnClickListener(new OnClickListener() { 
     public void onClick(View v) { 
      // Get the distance from the shared preferences 
      SharedPreferences preferences = PreferenceManager 
       .getDefaultSharedPreferences(getBaseContext()); 

      String distanceStr = preferences.getString("distance", "0"); 
      double distance = Double.parseDouble(distanceStr); 

      LocationManager locationManager = (LocationManager) getBaseContext() 
       .getSystemService(Context.LOCATION_SERVICE); 

      AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); 
      Intent intent = new Intent(LocationInfoActivity.this, 
       MyBroadcastReceiver.class); 
      PendingIntent pendingIntent = PendingIntent.getBroadcast(
       getBaseContext().getApplicationContext(), 234324243, 
       intent, PendingIntent.FLAG_UPDATE_CURRENT); 

      MyLocationListener locationListener = new MyLocationListener(
       locationManager, preferences, alarmManager, 
       pendingIntent); 

      if (distance < Double.parseDouble(i)) { 
       alarmManager.set(AlarmManager.RTC_WAKEUP, System 
         .currentTimeMillis(), pendingIntent); 
       locationManager.removeUpdates(locationListener); 
      } else if (distance < 4.0) { 
       WakeMeUtill.requestLocationUpdates(locationManager, 0, 0, 
         locationListener); 
      } else { 
       double quaterDistance = (distance * 3)/4; 
       WakeMeUtill.requestLocationUpdates(locationManager, 0, 
         (float) quaterDistance * 1000, locationListener); 
      } 
     } 
    }); 
} 
+0

你正在使用哪個設備/ Android版本? – Evgeny 2012-05-24 20:08:15

回答

0

可能是在你的代碼中的onPause寫此行()方法

onPause() 
{ 
    gpsLocationManager.removeupdates() 
} 

請檢查你的代碼。

如果這不是問題,請分享一些更多的細節。

相關問題