【问题标题】:Codename one Geofencing not firing代号一地理围栏未触发
【发布时间】:2016-04-21 18:15:45
【问题描述】:

我正在尝试对我的代号一个应用程序实施地理围栏。我按照 github 上的示例执行所有操作,但我的进入和退出方法似乎没有触发。我在构建提示中包含了 GPlayServices 以及 android.playService.* 和 ios.locationUsageDescription。

我已尝试使用 ios 和 android 设备对其进行测试。

下面是我的代码

在 onStart() 方法中

public void start() {
    if(current != null){
        current.show();
        return;
    }
    u = new UIBuilder();
    Display.getInstance().lockOrientation(true);

    Location loc = new Location();
    loc.setLatitude(-26.15739);
    loc.setLongitude(28.127099999999928);
    Geofence gf = new Geofence("test", loc, 1000, 100000);

 LocationManager.getLocationManager().addGeoFencing(GeofenceListenerImpl.class, gf);

    if (Preferences.get("userId", "error").equals("error")) {
        setUpLoginForm();
    } else {
        setUpMainPage();
    }
}

实现

public class GeofenceListenerImpl implements GeofenceListener {

public GeofenceListenerImpl() {

}

public void onExit(String id) {
    if(Display.getInstance().isMinimized()) {
        LocalNotification ln = new LocalNotification();
        ln.setId("LnMessage1");
        ln.setAlertTitle("Welcome");
        ln.setAlertBody("Thanks for arriving! isminimized");
        Display.getInstance().scheduleLocalNotification(ln, System.currentTimeMillis() + 1000, LocalNotification.REPEAT_NONE);
    } else {
        Display.getInstance().callSerially(new Runnable(){
            public void run() {
                Dialog.show("Welcome", "Thanks for arriving notminimized ", "OK", null);
            }
        });
    }
}

public void onEntered(String id) {
    if(Display.getInstance().isMinimized()) {
        LocalNotification ln = new LocalNotification();
        ln.setId("LnMessage2");
        ln.setAlertTitle("Welcome");
        ln.setAlertBody("Thanks for arriving! isminimized");
        Display.getInstance().scheduleLocalNotification(ln,  
System.currentTimeMillis() + 1000, LocalNotification.REPEAT_NONE);
    } else {
        Display.getInstance().callSerially(new Runnable(){
            public void run() {
                Dialog.show("Welcome", "Thanks for arriving   
notminimized ", "OK", null);
            }
        });
    }
}

}

【问题讨论】:

  • 你的 Main 类的完整代码是什么?

标签: android ios location codenameone geofencing


【解决方案1】:

通过谷歌挖掘后,我发现我必须添加构建提示:ios.background_modes=location 现在,当应用程序在设备上首次打开时,它会询问用户是否允许轮询他们在背景。但是地理围栏仍然没有触发,不过我会玩弄我的价值观。 android有类似的构建提示吗?因为在 android 设备上它甚至还没有提取位置。

【讨论】:

  • 可能是10米不够大,或者坐标不够准确。地理围栏是一个非常粗糙的 API,旨在在后台运行,因此要对其进行测试,您确实需要移动。
  • @ShaiAlmog 我的第三个参数是 100。所以不是 100 米而不是 10 米吗?还是你的意思是 100?
  • 也许不使用固定位置,而是使用 getCurrentLocationSync()?
  • @ShaiAlmog 我不能。我不想对用户的当前位置进行地理围栏,我想对城市中的某些地方进行地理围栏,以便在用户进入其中一个地方时收到通知。
  • 我不是这个意思。代码看起来很好,与我们的测试用例相似。我唯一无法验证的是坐标,通过使用从 getCurrentLocationSync() 获得的值,您可以有效地保证正确的设备坐标,然后您还可以将它们与您硬编码的坐标进行比较,并查看差异发生的位置。如果使用 getCurrentLocationSync() 失败,它会告诉我们一件事,如果它在这种情况下成功,它会告诉我们其他事情......
猜你喜欢
  • 2016-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多