我们有一个强大的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是的,我有所有权限设置 –