Gps 代号一个位置有时不工作

Gps 代号一个位置有时不工作,gps,location,codenameone,Gps,Location,Codenameone,老问题: 我们仍然无法获取当前位置 有时也可以,“Localizazione…”对话框显示,然后location ok回调处理该对话框 Slider s1 = new Slider(); Display.getInstance().callSerially(() -> { blocco_loc_in_corso = makeDialog("Localizzazione...", s1, null, 'a'); blocco_loc_in_corso.show(); });

老问题:

我们仍然无法获取当前位置

有时也可以,“Localizazione…”对话框显示,然后location ok回调处理该对话框

Slider s1 = new Slider();

Display.getInstance().callSerially(() -> {
    blocco_loc_in_corso = makeDialog("Localizzazione...", s1, null, 'a');
    blocco_loc_in_corso.show();
});

LocationManager locationManager = LocationManager.getLocationManager();
locationManager.setLocationListener(new LocationListener() {
    @Override
    public void locationUpdated(Location location) {
        if(location != null) {
            Display.getInstance().callSerially(() -> {
                if(blocco_loc_in_corso != null) {
                    blocco_loc_in_corso.dispose();
                }
            });
            paintLocation(location, true);
        }
    }

    @Override
    public void providerStateChanged(int newState) {

    }
}, new LocationRequest(LocationRequest.PRIORITY_HIGH_ACCUARCY, 1000));
有时,对话框从未被释放,我在顶部栏中看不到GPS,当位置确定并释放对话框时,可以看到GPS

Slider s1 = new Slider();

Display.getInstance().callSerially(() -> {
    blocco_loc_in_corso = makeDialog("Localizzazione...", s1, null, 'a');
    blocco_loc_in_corso.show();
});

LocationManager locationManager = LocationManager.getLocationManager();
locationManager.setLocationListener(new LocationListener() {
    @Override
    public void locationUpdated(Location location) {
        if(location != null) {
            Display.getInstance().callSerially(() -> {
                if(blocco_loc_in_corso != null) {
                    blocco_loc_in_corso.dispose();
                }
            });
            paintLocation(location, true);
        }
    }

    @Override
    public void providerStateChanged(int newState) {

    }
}, new LocationRequest(LocationRequest.PRIORITY_HIGH_ACCUARCY, 1000));
我有这个问题至少6个月了。我们只需要阻止用户,直到我们有他的GPS位置可能会改变(GPS更新回调)

编辑:

public Dialog makeDialog(String label, Component c, String buttonText, char btIcon) {
    Dialog dlg_r = new Dialog();
    Style dlgStyle = dlg_r.getDialogStyle();
    dlgStyle.setBorder(Border.createEmpty());
    dlgStyle.setBgTransparency(255);
    dlgStyle.setBgColor(0xffffff);

    Label title = dlg_r.getTitleComponent();

    title.getUnselectedStyle().setFgColor(0xff);
    title.getUnselectedStyle().setAlignment(Component.LEFT);

    dlg_r.setLayout(BoxLayout.y());

    Label blueLabel = new Label(label);
    blueLabel.setShowEvenIfBlank(true);
    blueLabel.getUnselectedStyle().setBgColor(0xff);
    blueLabel.getStyle().setFgColor(0x0a0afc);
    blueLabel.getStyle().setAlignment(Component.CENTER);
    blueLabel.getUnselectedStyle().setPadding(1, 1, 1, 1);
    blueLabel.getUnselectedStyle().setPaddingUnit(Style.UNIT_TYPE_PIXELS);
    dlg_r.add(blueLabel);
    dlg_r.add(c);
    if (buttonText != null) {
        Button dismiss = new Button(buttonText);
        dismiss.getAllStyles().setBorder(Border.createEmpty());
        dismiss.getAllStyles().setFgColor(0);
        dismiss.getAllStyles().set3DText(true, true);
        dismiss.setIcon(FontImage.createMaterial(btIcon, dismiss.getStyle()));
        dismiss.addActionListener(((evt) -> {
            dlg_r.dispose();
        }));
        dlg_r.add(dismiss);
    }
    return dlg_r;
}

要确保此代码是线程安全的,请进行以下更改:

public void locationUpdated(Location location) {
    locationFound = true;
    // ...
}
然后在“生成”对话框方法中:

dlg_r.addShowListener(e -> {
     if(locationFound) {
         dlg_r.dispose();
     }
});

由于此事件可能发生在显示对话框转换的死区时间。

要确保此代码是线程安全的,请进行以下更改:

public void locationUpdated(Location location) {
    locationFound = true;
    // ...
}
然后在“生成”对话框方法中:

dlg_r.addShowListener(e -> {
     if(locationFound) {
         dlg_r.dispose();
     }
});

由于此事件可能发生在显示对话框转换的死区时间。

我需要查看
makeDialog
的代码,如果调用了
locationUpdated
,则通常不会显示该代码。登录
providerStateChanged
只是为了确保一切正常。我用
makeDialog
code编辑了答案。我需要查看
makeDialog
的代码,如果调用了
locationUpdated
,通常根本不应该显示该代码。登录
providerStateChanged
以确保一切正常也会很有趣。我用
makeDialog
code编辑了答案不幸的是,我们试图重现您遇到的问题,但没有成功。不幸的是,我们试图重现您遇到的问题,但没有成功目前为止