gluon-mobile - 如何使用具有不同参数(如精度、时间间隔等)的 start() 方法启动胶子移动 PositionService
问题描述
目前我正在使用胶子移动 PositionService 来检测用户当前位置。但我想使用参数 API 为 PositionService 配置不同的设置。但是当我使用 start(Parameters parameters) 时,我被重定向到 android 应用程序中的位置设置。请告诉我使用参数配置和启动此服务的最佳方法是什么。
public void initialize() {
try {
setupLocationService();
} catch (Throwable t) {
LOGGER.log(Level.SEVERE, "Error setting up location service", t);
}
}
private void setupLocationService() {
LOGGER.log(Level.INFO, "Register position service ");
Services.get(PositionService.class).ifPresent(ps -> {
// If I uncomment following line the application presenter is not displayed
// Instead I see the Location menu in anroid settings page when user has to manulaly enable the location
//ps.start(new Parameters(Parameters.Accuracy.LOW, LocationSynchronizer.ACCEPTABLE_TIMEFRAME, LocationSynchronizer.ACCEPTABLE_ACCURACY, true));
ps.positionProperty().addListener(e -> {
Position position = ps.getPosition();
if (position != null) {
// sync location using rest API
locationSynchronizer.syncronizeLocations(position);
}
});
});
}
解决方案
推荐阅读
- c# - Project 引用的 DataSetExtensions 并使用 System.Data 但扩展方法不可用
- qemu - Debian 10 上的 NFS 服务器,虚拟机无法挂载
- reactjs - DraftJS:nextEditorState.getDirectionMap 不是函数
- google-sheets - 公式 - 基于 2 个条件的标准偏差
- python - 如何创建用于带发票的条带订阅的付款来源
- mysql - 使用 MySQL 检查重复访问和更新表
- html - 调整 SVG 背景宽度和高度
- python - 更新或添加验证器到现有的 WTForms 字段
- android - 如何在 Google Maps Android SDK 的折线上添加形状
- php - 使用 ansible 管理 php 配置 - lineinfile php.ini vs 复制到 php.d?