首页 > 解决方案 > 如何使用具有不同参数(如精度、时间间隔等)的 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);
                }
            });
        });
    }

标签: gluon-mobile

解决方案


推荐阅读