- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如果我们想在 Android 中获得单个 GPS 定位,我们实际上会使用带有 LocationManager.GPS_PROVIDER 的已知函数 requestSingleUpdate(),对吗?
现在我在我的函数 getLocation() 中执行此操作并打开了 GPS,但设备不会自动建立连接,除非我手动关闭 GPS 然后再次打开它。网络提供商的 requestSingleUpdate() 工作完美,我只是不知道为什么这不适用于 GPS 修复。
这是我的源代码的一部分:
getLocation() 由另一个对象每 2 分钟运行一次。在 getLocation() 中,如果 GPS 和网络已打开,它会尝试在第一分钟内获取 GPS 定位,然后获取网络位置,如果没有可用的 GPS 定位。
public boolean getLocation() {
// DEBUG
Log.d("GPS Connection", "Entering getLocation()");
gpsEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
networkEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
if(!gpsEnabled && !networkEnabled)
return false;
if(gpsEnabled && networkEnabled) {
// DEBUG
Log.d("GPS Connection", "Request GPS Data");
locationManager.requestSingleUpdate(LocationManager.GPS_PROVIDER, gpsLocationListener, Looper.getMainLooper());
gpsGetLocationTimeout = new Timer();
gpsGetLocationTimeout.schedule(new GetNetworkLocation(), GPS_MAX_CONNECTION_TIME_MS);
}
...
最佳答案
It may take a while to receive the most recent location. If an immediate location is required, applications may use the getLastKnownLocation(String) method. In case the provider is disabled by the user, the update will not be received, and the onProviderDisabled(String) method will be called. As soon as the provider is enabled again, the onProviderEnabled(String) method will be called and location updates will start again.
GPS 可能需要很长时间才能冷启动。如果您在室内、 parking 场、被高楼环绕、手机质量很差,或者 GPS 卫星大神心情不好,您可能永远无法获得 GPS。
在某些应用程序中,我们会做一些事情,比如请求 GPS 位置,然后如果它在 60 秒后仍未到达,则取消请求,这样我们就不会在 GPS RX 半永久开启的情况下耗尽手机电池.
您可以请求最后一个已知位置并检查其使用年限并确定它是否足够新以供使用。网络定位快速且便宜(就电池使用而言),一个好的策略是在获得 GPS 之前使用网络定位。
我在 Android 中编写 GPS 代码的经验是,GPS 会做它想做的事情,这在很多方面都不是文档引导您期望的事情。 GPS 需要被视为可能可用或不可用的东西,您的程序逻辑可以设计为处理该问题。
关于java - requestSingleUpdate(...) 不会自动获取 GPS 位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10405277/
我正在关注 Android Location Deep Dive tutorial .在部分代码中,接收者是这样注册的。 IntentFilter locIntentFilter = new Inte
我正在开发应用程序,它必须获得纬度和经度。在我的例子中,requestLocationUpdates (String provider, long minTime, float minDistance
如果我们想在 Android 中获得单个 GPS 定位,我们实际上会使用带有 LocationManager.GPS_PROVIDER 的已知函数 requestSingleUpdate(),对吗?
我正在使用 android LocationManager 的例程 requestSingleUpdate() 重例程带有 LocationListener 的库.我正在尝试实现的功能是用户可以按下按
在我的应用程序中,我使用了 requestSingleUpdate() 方法,它在所有设备上都运行良好,但在某些设备 2.3 android 操作系统版本中,GPS 无法获取位置。这是代码, Inte
我是一名优秀的程序员,十分优秀!