強力な GPS 信号があります。GPS ロックが確立される速度をテストするためのアプリがあります。携帯電話でナビゲーション アプリをテストしたところ、GPS をオンにしただけで、すべて 10 秒以内でほぼ瞬時にロックされます。
しかし、このアプリでは、ロックを取得することはありません。ワイル ループが延々と続くだけで、ログには 10 分間実行しても何も表示されません。10 分を超える遅延が発生する可能性があることはわかっていますが、lastKnownLocation を使用せずに実際の場所を取得している他のアプリには問題はありません。
また、gpsLocation() メソッドは静的 Locator クラスにあります。
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
Location location = Locator.gpsLocation(this);
while(location == null)
{
location = Locator.gpsLocation(this);
}
Log.w("GPS LOCATION", "LOCATION FOUND");
}
/**
* Finds users location using gps
* satelite network.
*
* @param FragmentActivity
* @return Location
*/
public static Location gpsLocation(FragmentActivity context)
{
// Fetch LocationManager service & instance of UserLocator
LocationManager provider = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
UserLocator locator = new UserLocator();
// Attempt to get a fix on users location
provider.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locator);
// Return users location using GPS Service
return locator.location;
}
/**
* Use to listen for user location updates
* TODO: Reimplement as a anonymous class
*/
class UserLocator implements LocationListener
{
// Public accessor
public Location location;
public void onLocationChanged(Location location)
{
if(location != null)
{
// We have a fix on users location
this.location = location;
}
}
public void onProviderDisabled(String provider) {}
public void onProviderEnabled(String provider) {}
public void onStatusChanged(String provider, int status, Bundle extras) {}
}