Codename一个应用程序未提供真实位置

问题描述 投票:1回答:1

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

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

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

为了获取位置,我们使用此:

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());
    }
}

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


ADDED 25/04/2020 11:58我忘了说,大约有40%的案件到达“获取最后的已知地点...”,然后给出了理想的真实位置。Android构建提示:enter image description here

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

<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"/>
geolocation codenameone android-gps
1个回答
0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.