現在地の GPS 座標を取得しようと懸命に努力していますが、アプリが GPS 衛星にロックしません。
通知領域の GPS アイコンが点滅し続けます。
AndroidでGoogleマップ(プリインストールアプリ)を使ってみたところ、約60秒でロックオンできました!どちらの場合も、3G データ接続はオンになっており、機能していました。
更新: Android 2.3.3 (HTC Desire S (工場でインストールされた OS、更新は適用されていません)) を使用しています。Logcat の出力はこちらです。現在、これはLocationUpdates()
の最小時間と更新間の最小距離を 0, 0 に設定していません。
更新 #2:以前のコードはこちら(PasteBin リンク)。
更新 #3:今、トースト .."Available".. を on に表示した後、強制終了していonStatusChanged()
ます。
更新 #4:最後に..動作するようになりました。
--
ということは、Google マップのアプリが GPS 信号をロックするために独自のコードを使用しているようなものですか? さまざまなバージョンのコードを使用してみました。基準を使用してみましたが、GPS で機能することはありませんでした。私にとって、GPS を介して正確な (~50 フィートの精度) 位置座標を取得することは必須です。
私のコード:
public class LocationDemoActivity extends Activity implements LocationListener {
LocationManager locationManager;
StringBuilder builder;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000l, 50.0f, this);
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
locationManager.removeUpdates(this);
locationManager = null;
Intent i = new Intent(
android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(i);
}
@Override
public void onLocationChanged(Location location) {
// builder = new StringBuilder();
double lati=location.getLatitude();
double longi=location.getLongitude();
double alti=location.getAltitude();
float acc=location.getAccuracy();
float speed=location.getSpeed();
long time=location.getTime();
System.out.println(lati);
System.out.println(longi);
System.out.println(alti);
System.out.println(acc);
System.out.println(speed);
System.out.println(time);
/*Toast.makeText(this, "Lati: " + lati,Toast.LENGTH_SHORT).show();
Toast.makeText(this, "Long: " + longi,Toast.LENGTH_SHORT).show();
Toast.makeText(this, "Alti: " + alti,Toast.LENGTH_SHORT).show();
Toast.makeText(this, "Acc.: " + acc,Toast.LENGTH_SHORT).show();
Toast.makeText(this, "Speed: " + speed,Toast.LENGTH_SHORT).show();
Toast.makeText(this, "Time: " + time,Toast.LENGTH_SHORT).show();*/
builder.append("Longitide: " + location.getLongitude());
builder.append('\n');
builder.append("Latitude: " + location.getLatitude());
builder.append('\n');
builder.append("Altitude: " + location.getAltitude());
builder.append('\n');
builder.append("Accuracy: " + location.getAccuracy());
builder.append('\n');
builder.append("TimeStamp:" + location.getTime());
builder.append('\n');
System.out.println(builder.toString());
Toast.makeText(this, builder.toString(), Toast.LENGTH_LONG).show();
}
@Override
public void onProviderDisabled(String provider) {
System.out.println("Provider Disabled:");
Intent intent = new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(intent);
}
@Override
public void onProviderEnabled(String provider) {
System.out.println("Provider Enabled:");
Toast.makeText(this, "GPS is now enabled...", Toast.LENGTH_LONG).show();
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
switch (status) {
case LocationProvider.OUT_OF_SERVICE:
System.out.println("Status Changed: Out of Service");
Toast.makeText(this, "Status Changed: Out of Service",
Toast.LENGTH_SHORT).show();
break;
case LocationProvider.TEMPORARILY_UNAVAILABLE:
System.out.println("Status Changed: Temporarily Unavailable");
Toast.makeText(this, "Status Changed: Temporarily Unavailable",
Toast.LENGTH_SHORT).show();
break;
case LocationProvider.AVAILABLE:
System.out.println("Status Changed: Available");
Toast.makeText(this, "Status Changed: Available",
Toast.LENGTH_SHORT).show();
break;
}
}
}
それは私にとって非常に緊急であり、どんな助けも非常に価値があるので答えてください:)
ありがとう..