ありがとうコムズウェア。コメント欄のスペースが限られているため、この方法で返信しています。
ユーザーは、ピックアップしようとしているアイテムの写真を撮り、それをサーバーに送信することになっています。これが完了すると、サーバーは電話が定期的に位置情報を送信するようにポーリング サイクル期間を返します。取得した緯度/経度を表示するように をセットアップしましたが textViews
(以下を参照)、この部分は 2 日前まで機能していませんでした。もう少し辛抱して、電話が位置を取得するのに時間がかかるようにした後、ようやく機能しました。当時の問題は、電話が位置修正を取得することを許可していなかったため、機能していなかったと思います。あなたが言ったことに基づいて、そして位置修正を得る前に約2分間完全に晴れた空の下で外に立っていたという事実に基づいて、定期的な更新が機能しない可能性があるという問題が残っています。
コードの一部のスナップショットを次に示します (この部分は、最初の場所の修正を取得するためのメイン アクティビティの onCreate オーバーライドにあります)。
`LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0,
0, new LocationListener() {
public void onStatusChanged(String provider, int status,
Bundle extras) {
// called when the provider status changes. Possible
// status: OUT_OF_SERVICE, TEMPORARILY_UNAVAILABLE or
// AVAILABLE.
}
public void onProviderEnabled(String provider) {
// called when the provider is enabled by the user
}
public void onProviderDisabled(String provider) {
// called when the provider is disabled by the user, if
// it's already disabled, it's called immediately after
// requestLocationUpdates
}
public void onLocationChanged(Location location) {
double latitute = location.getLatitude();
double longitude = location.getLongitude();
tv5.setText(""+latitute);
tv6.setText(""+longitude);
}
});
`
以下は、SOAP 要求および応答処理メカニズムの一部です。
//ポーリング期間を秒単位で取得します。文字列[] getPollNumber; getPollNumber = resultParams[2].split(";");
//Set up the intent to be passed to the tracking service.
Intent updateLocation = new Intent (this,TrackUser.class);
PendingIntent pendingIntent = PendingIntent.getService(PickUp.this, 0, updateLocation, 0);
//Set up the alarm manager to be used to periodically send updates.
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
//If instruction = 1, start tracking the user.
if(instruction == 1)
{
//Start tracking service on phone.
pollPeriod = Integer.parseInt(getPollNumber[0]);
alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + (pollPeriod*1000), pollPeriod*1000, pendingIntent);
}
else
{
if(instruction == 0)
{
//Stop tracking service.
stopService(new Intent(this,TrackUser.class));
alarmManager.cancel(pendingIntent);
}
}
'
追跡サービス クラスでは、現在の座標を SOAP オブジェクトに単純にパッケージ化し、サーバーを更新する onStart() オーバーライドから呼び出されるメソッドを使用します。あなたが言ったように電話がスリープ状態になった場合、これらの更新中にGPSがロックするのに十分な時間がないのではないかと心配しています. サービスが開始されたときに、何らかのタイマー (requestLocationUpdates の minTime 設定など) を用意する必要があるかどうか疑問に思っています。電話を約 3 分間待機させて、修正が行われるようにしますか? これらのコード スニペットが役立つかどうか、および位置を更新するためのアイデアが可能かどうかをお知らせください。