android – onLocationChanged只调用一次,而不是刷新

我做了一个小gps应用程序由于某种原因onLocationChanged没有刷新,它只在app启动时运行一次.

这是我的代码

public BackgroundLocationService() {
        super("myintentservice");

        locManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);

        Criteria crt = new Criteria();
        crt.setAccuracy(Criteria.ACCURACY_FINE);
        String bestProvider = locManager.getBestProvider(crt,true);

        boolean gps_enabled;
        boolean network_enabled;
        boolean best_enabled;

        gps_enabled = locManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
        network_enabled = locManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
        best_enabled = locManager.isProviderEnabled(bestProvider);


        if (best_enabled) {
            locManager.requestLocationUpdates(bestProvider,15000,20,locListener);
            Log.i(TAG,"Best enabled: " + bestProvider);
        } else {
            Log.i("Location Provider: ","best not enabled: " + bestProvider);
            if (gps_enabled) {
                locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,locListener);
                Log.i(TAG,"gps enabled!");
            }
            if (network_enabled) {
                locManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,"network enabled!");
            }
        }

    }



    class MyLocationListener implements LocationListener {
        public void onLocationChanged(Location location) {

            if (location != null) {

                //locManager.removeUpdates(locListener);
                longitude = Double.toString(location.getLongitude());
                latitude = Double.toString(location.getLatitude());

                Log.i(TAG,"Location has CHANGED!");
            }
        }
        public void onProviderdisabled(String arg) {}
        public void onProviderEnabled(String arg) {}
        public void onStatusChanged(String provider,int status,Bundle extras) {}
    }

“地点已经改变了!”消息仅在每个应用启动时显示一次.
我在办公室,但我可以移动至少5-10米远离我的位置,所有提供商都启用,所以它一定是好的,不是吗?

有任何想法吗 ?

解决方法

注册位置监听器时,您要求的最新时间为15秒,最小距离为20米.由于你在办公室内,你不太可能获得足够准确的GPS定位来实际检测到5-10米的移动.你有没有试过外面调试?同样,如果您启用了模拟位置,请将模拟坐标发送到模拟器,以确保您的应用在更新位置时按预期运行.

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...