代号一个应用程序未提供真实位置 [英] Codename One app not provide real location

查看:64
本文介绍了代号一个应用程序未提供真实位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

输入输出应用程序中,我们有一个模块,您可以在其中发送带有GPS位置的时间记录.

in out app we have a module where you can send time records with GPS location.

在40%的情况下,我们遇到了位置问题,因为该模块提供的位置不是真实的(有时约1公里).

In 40% of cases we have location problem because the module provides a location which is not real (sometime about 1 km away).

遇到这种情况时,我们打开Goog​​le Maps应用程序,它会为我们提供理想的位置,然后再次显示该应用程序,而不是真实位置.

When we have this cases we open Google Maps app and it give us perfect location, then again out app and not-real location.

要获取位置,我们使用以下方法:

For getting the location we use this:

Slider s1 = new Slider();
Dialog dlg = makeDialog("HIGH PRECISION LOCATION...", s1, null, 'a');
dlg.addShowListener((ActionListener) e -> {

    LocationManager locationManager = LocationManager.getLocationManager();                
    locationManager.setLocationListener(this, new LocationRequest(LocationRequest.PRIORITY_HIGH_ACCUARCY, 500));

    loc = locationManager.getCurrentLocationSync(20000);

    dlg.dispose();
    if(loc == null) {
        Slider s2 = new Slider();
        Dialog dlg2 = makeDialog("GETTING LAST KNOWN LOCATION...", s2, "OK", 'a');
        dlg2.addShowListener((ActionListener) e2 -> {
            loc = locationManager.getLastKnownLocation();

            if(loc == null) {
                // location not found
                Dialog.show("Attenzione!", "Posizione non trovata. E' consigliato di spostarsi all'aperto. "
                        + "Tuttavia è possibile inviare la timbratura anche senza coordinate.", "Ok", null);
            } else {
                paintLocation(loc, GPSStateOn);
            }
        });
        dlg2.show();
    } else {
        paintLocation(loc, GPSStateOn);
    }

});
dlg.show();

-

@Override
public void locationUpdated(final Location location) {

    switch (LocationManager.getLocationManager().getStatus()) {
        case LocationManager.AVAILABLE:
            GPSStateOn = true;
            break;
        case LocationManager.OUT_OF_SERVICE:
            GPSStateOn = false;
            break;                
        case LocationManager.TEMPORARILY_UNAVAILABLE:
            GPSStateOn = false;                 
            break;                
    }

    if(loc != null) {
        paintLocation(loc,GPSStateOn);
        System.out.println("-----LATITUDINE: " + loc.getLatitude());
        System.out.println("-----LONGITUDINE: " + loc.getLongitude());
    }
}

我们还添加了提示提示 android.playService.location = true

We also have added the buil hint android.playService.location = true


已添加2020年4月25日11:58 我忘了说,大约有40%的案件是到达获得最后知道的地点...",然后给出了理想的真实位置.Android构建提示:


ADDED 25/04/2020 11:58 I forgot to say that about 40% of cases it arrives at "GETTING LAST KNOWN LOCATION..." and then give perfect real location. Android build hints:

最后一个被切掉...值是:

last one is cutted... value is:

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/><uses-feature         android:glEsVersion="0x00020000"         android:required="true"/><uses-permission android:name="android.permission.CAMERA"/><uses-feature android:name="android.hardware.camera" android:required="false"/>


已添加2020年6月5日10:48

也许这可能是有用的:我注意到当位置过多时,GPS图标不会显示在顶部栏中

Maybe this can be useful: I noticed when the location takes a lot the GPS icon isn't displayed in the topbar

当花费更少的时间时,GPS图标可见

And when it takes less time the GPS icon is visible

推荐答案

再次查看代码,我发现您使用了set location侦听器和 getCurrentLocationSync ,在这种情况下,它们是互斥的.您需要选择一个.如果您给前者(这是首选方法)足够的时间来工作,它应该会为您提供准确的位置.请注意,GPS位置有时需要几秒钟的时间才能进行初始读取.

Looking again at the code I noticed you used set location listener and getCurrentLocationSync which are mutually exclusive in this case. You need to pick one. If you give the former (which is the preferred way) enough time to work it should give you an accurate location. Notice the GPS position sometimes needs a couple of seconds for the initial reading.

这篇关于代号一个应用程序未提供真实位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆