我在做一个GPS定位程序,只需要获取当前的经纬度即可。
我通过LocationListener接口监听位置是否有变动。
然后通过public void onLocationChanged(Location location)方法获取地址信息:
        lat = location.getLatitude();
        lng = location.getLongitude();
但是当我把GPS关闭,并且打开基站定位的时候,这个方法依然会被调用到,并且返回的是基站的经纬度(通过LAC和CellID到google的接口获取)。
请问在程序中如何判断这个数据是GPS获取的经纬度还是基站信息转的经纬度。

解决方案 »

  1.   

    判断下location provider的变化,比如是gps还是network提供的定位方式就行了
      

  2.   

    public static final String NETWORK_PROVIDER = "network";
    public static final String GPS_PROVIDER = "gps";调用下面接口传true就可以。    /**
         * Returns a list of the names of location providers.  Only providers that
         * are permitted to be accessed by the calling activity will be returned.
         *
         * @param enabledOnly if true then only the providers which are currently
         * enabled are returned.
         * @return list of Strings containing names of the providers
         */
        public List<String> getProviders(boolean enabledOnly) {
            try {
                return mService.getProviders(enabledOnly);
            } catch (RemoteException ex) {
                Log.e(TAG, "getProviders: RemoteException", ex);
            }
            return null;
        }
      

  3.   


    你这段代码是你某个程序的一部分?mService是什么?返回什么?
      

  4.   

    这段代码是Android的实现,你直接调用接口就可以了。
      

  5.   

    mService是LocationManager的对象,通过Context.getSystemService(Context.LOCATION_SERVICE)来实例化,当然,除了我说的方法外,判断gps状态也行,实现android.location.GpsStatus.Listener这个接口,重写onGpsStatusChanged(int event) 这个方法,gps状态有GPS_EVENT_STARTED 
    GPS_EVENT_STOPPED 
    GPS_EVENT_FIRST_FIX 
    GPS_EVENT_SATELLITE_STATUS