我們有一個強大的GPS信號,我有測試GPS鎖定有多快能夠建立我甚至測試了我的手機上的導航軟件,他們都得到了應用相當,如果我多斯塔鎖波紋管10只打開GPS。應用程序從未收到GPS定位
但有了這個程序,我只是從來沒有得到一個鎖,詭計循環只是不斷走下去,和日誌從來沒有顯示我讓它運行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) {}
}
您是否聲明瞭您的權限? – Bob
@Bob是的,我有所有權限設置 –