如何中断 getCurrentLocation 方法(Codename One Location Manager)?
How can I interrupt getCurrentLocation method (Codename One Location Manager)?
我的应用有一张地图,当用户长按它时,我需要当前 phone 位置显示在地图上。正如@Chen advised 看起来 getCurrentLocation() 是在我的情况下使用的正确方法。请注意,我不想使用 LocationListener,因为我希望用户可以控制何时更新他们的位置。
此外,我选择了此手动位置更新,因为@Shai-Almog . So after reading this 我首先将超时设置为 20 秒,如下所示,以获取当前 phone 位置:
Dialog ip = new InfiniteProgress().showInifiniteBlocking();
Location currentLocation = locationManager.getCurrentLocationSync(
ParametresGeneraux.LOCATION_TIMEOUT_MILLI);
// We try to get something
if (currentLocation == null) {
currentLocation = locationManager.getLastKnownLocation();
}
ip.dispose();
但这还不够,虽然工具栏中出现了小位置图标,但最后已知的位置是 "always" 提供的(我可能连续 5 次都没有计算)。所以我将它设置为 40 秒,但实际的当前位置在两倍的时间之后也没有出现(只提供了 > 2 公里以外的最后一个已知位置)。
但是,如果我在 Android (KitKat) 上启动 Google 地图,位置会立即准确。然后,如果我回到我的应用程序并按地图,就会找到当前位置。事实上,我发现 post 处理 Google 地图和 Android API 之间的准确性差异,但它与上海/中国有关,而不是欧盟(法国)。
因此我的问题是双重的:
首先Google地图和代号一在同一台设备上怎么会有这么大的差异?
那么如果我不设置超时 getCurrentLocation()
如何在用户厌倦等待时中断位置搜索?
感谢任何帮助,
BR
如果 Google 地图定位服务已打开,即时定位将可用。如果您启用或禁用了 android.playService
构建提示之一,您还必须启用 android.playService.location=true
才能获得地图使用的快速定位服务。
我的应用有一张地图,当用户长按它时,我需要当前 phone 位置显示在地图上。正如@Chen advised 看起来 getCurrentLocation() 是在我的情况下使用的正确方法。请注意,我不想使用 LocationListener,因为我希望用户可以控制何时更新他们的位置。
此外,我选择了此手动位置更新,因为@Shai-Almog
Dialog ip = new InfiniteProgress().showInifiniteBlocking();
Location currentLocation = locationManager.getCurrentLocationSync(
ParametresGeneraux.LOCATION_TIMEOUT_MILLI);
// We try to get something
if (currentLocation == null) {
currentLocation = locationManager.getLastKnownLocation();
}
ip.dispose();
但这还不够,虽然工具栏中出现了小位置图标,但最后已知的位置是 "always" 提供的(我可能连续 5 次都没有计算)。所以我将它设置为 40 秒,但实际的当前位置在两倍的时间之后也没有出现(只提供了 > 2 公里以外的最后一个已知位置)。
但是,如果我在 Android (KitKat) 上启动 Google 地图,位置会立即准确。然后,如果我回到我的应用程序并按地图,就会找到当前位置。事实上,我发现 post 处理 Google 地图和 Android API 之间的准确性差异,但它与上海/中国有关,而不是欧盟(法国)。
因此我的问题是双重的:
首先Google地图和代号一在同一台设备上怎么会有这么大的差异?
那么如果我不设置超时
getCurrentLocation()
如何在用户厌倦等待时中断位置搜索?
感谢任何帮助,
BR
如果 Google 地图定位服务已打开,即时定位将可用。如果您启用或禁用了 android.playService
构建提示之一,您还必须启用 android.playService.location=true
才能获得地图使用的快速定位服务。