三星Galaxy2不正确的GPS定位 [英] Incorrect GPS location on Samsung Galaxy2

查看:177
本文介绍了三星Galaxy2不正确的GPS定位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的三星Galaxy2(Android版2.3.5)调查的GPS位置。 SG2支持A-GPS,所以我把GPS,Wifi网络与传感器上的帮助。它看起来运行良好,但有时GPS给人完全不同的位置50余公里远从我的当前位置。另外,位置经常变化,即使我只是把手机上的一个点,从来没有感动。

I am investigating GPS location on Samsung Galaxy2 (Android 2.3.5). SG2 supports A-GPS, so I turned GPS, Wifi network and Sensor aiding on. It looks working well but sometimes the GPS gives completely different location more than 50km far from my current place. Also the location changes often even though I just put on the phone one spot and never touched.

我还是新到Android,所以我不知道是什么原因导致了这个问题。下面是源$ C ​​$ C处理GPS定位:

I am still new to Android, so I not sure what causes this problem. Below is the source code handling GPS location.:

public class LocationMonitor extends Service implements LocationListener,Runnable {
    .... other local variables here

    Object locationUpdateNotifier= null;
    public static GeoPoint ourLocation;


    public void synchronize()
    {
        if(ourLocation == null)
        {
            ourLocation = getLastKnownLocation();
            if(ourLocation == null) return;
        }

        //Load last time we synced
        long lastSyncTime = some_value;

        if(lastSyncTime < System.currentTimeMillis()  - UPDATE_FREQ)  //UPDATE_FREQ - default 30 minutes
        {
            handler.post(new Runnable() {
                public void run() {
                    GpsPingTask pingTask = new GpsPingTask(context,String.valueOf(ourLocation.getLatitudeE6()/1E6),String.valueOf(ourLocation.getLongitudeE6()/1E6));
                    pingTask.execute((Void)null); //Send location to server
                }
            });
            lastSyncTime =  System.currentTimeMillis();
            //Save new lastSync time 
        }
    }



    public void kill()
    {
        if(locationManager !=null)
            locationManager.removeUpdates(this);
    }

     public void onLocationChanged(Location location) {
        try
        {
            //Read latitude and longitude from location
            //Create Geo point so we can get a english street name address
            ourLocation = new GeoPoint((int)(location.getLatitude()*1E6),(int)(location.getLongitude()*1E6));

            if(locationUpdateNotifier != null)
            {
                synchronized (locationUpdateNotifier) {
                    locationUpdateNotifier.notify();
                }
            }

            if(!doneFirstUpdate)
            {
                doneFirstUpdate =true;
                Log.i("LocationMointor", "LocationMonitor.onLocationChanged() done first update at 0 frequency, resetting to normal speed");
                //Set it to update at the requested frequency
                resetLocationUpdatesFreq();
            }

            startSynchronizeThread();
        }
        catch (Throwable e) {
            Log.i("LocationMointor", "LocationMonitor.onLocationChanged(): " + e);
        }
    }


    public void onProviderDisabled(
            String provider) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onProviderEnabled(String provider) {}

    @Override
    public void onStatusChanged(String provider, int status, Bundle extras) {}


    public void setTemporaryLocationUpdateFreq(int pingFreqSecs) {

        setTemporaryLocationUpdateFreq(pingFreqSecs, 10);
    }


    public void setTemporaryLocationUpdateFreq(int pingFreqSecs, int minimumDistanceMeters) {
        if(!doneFirstUpdate)
            doneFirstUpdate =true;

        tempLocationUpdateFreq = pingFreqSecs;
        tempLocationUpdateMeters = minimumDistanceMeters;
        handler.post(new Runnable()
        {
            public void run() {
                //Turn of location updates
                if(locationManager !=null)
                    locationManager.removeUpdates(locationMonitor);
                //Restart  location updates with new frequency
                locationManager.requestLocationUpdates(getGpsMode(), UPDATE_FREQ, tempLocationUpdateMeters,locationMonitor);
                //locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, tempLocationUpdateFreq*1000, tempLocationUpdateMeters,locationMonitor);
            }
        });
    }

    private void startSynchronizeThread() {
        if(!running)
            new Thread(this).start();
    }


    public void resetLocationUpdatesFreq() {
        locationUpdateNotifier = null;
        handler.post(new Runnable()
        {
            public void run() {
                //Turn of location updates
                if(locationManager !=null) {
                    locationManager.removeUpdates(locationMonitor);
                    //Restart  location updates with default location update frequency
                    //locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, MINIMUM_TIME_BETWEEN_UPDATE, MINIMUM_DISTANCECHANGE_FOR_UPDATE,locationMonitor);
                }
            }
        });
    }


    public void setLocationUpdateFreq(int pingFreqMins) {

        Log.i("LocationMointor", "LocationMonitor.setLocationUpdateFreq().mode: " + getGpsMode() + "pingFreq:" + pingFreqMins);

        //Save new frequency value
        SharedPreferences pref = context.getSharedPreferences(PREF_PING_FREQ, Context.MODE_PRIVATE);
        Editor prefEditor=  pref.edit();
        prefEditor.putInt(PREF_PING_FREQ, 10);
        prefEditor.commit();
        handler.post(new Runnable()
        {
            public void run() {
                //Turn of location updates
                if(locationManager !=null)
                    locationManager.removeUpdates(locationMonitor);
                //Restart  location updates with new piong frequency
                locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, MINIMUM_TIME_BETWEEN_UPDATE, MINIMUM_DISTANCECHANGE_FOR_UPDATE,locationMonitor);
            }
        });

    }


    public void addUpdateNotify(Object notifyable)
    {
        this.locationUpdateNotifier = notifyable;
    }


    public GeoPoint getLastKnownLocation()
    {
        Criteria crit = new Criteria();
        //Try get last known fine location
        crit.setAccuracy(Criteria.ACCURACY_FINE);
        String provider = locationManager.getBestProvider(crit, false);
        Location loc = locationManager.getLastKnownLocation(provider);
        //If we got no location, try coarse location
        if(loc == null)
        {

            crit.setAccuracy(Criteria.ACCURACY_COARSE);
            provider = locationManager.getBestProvider(crit, false);
            loc = locationManager.getLastKnownLocation(provider);
            //If nothing, return nothing
            if(loc == null)
            {
                Log.i("LocationMointor", "LocationMonitor.getLastKnownLocation() got no location");
                return null;
            }
        }

        //Create geopoint and return it.
        GeoPoint geoPoint = new GeoPoint((int)(loc.getLatitude()*1E6),(int)(loc.getLongitude()*1E6));
        Log.i("LocationMointor", "LocationMonitor.getLastKnownLocation() got "  +geoPoint);

        return geoPoint;
    }

    @Override
    public void run() {
        running = true;
        Object pauser = new Object();
        do{
            try
            {
                synchronize();
                synchronized(pauser)
                {
                    pauser.wait(UPDATE_FREQ);
                }

            }
            catch(Throwable ex)
            {
                Log.e("LocationMointor", "LocationMonitor.run() " +ex);
            }
        }
        while(running);
    }

    public void onCreate() {
        super.onCreate();

        this.context = this;
        this.locationMonitor= this;

        handler = new Handler(); 

        //Get the location manager service
        locationManager = (LocationManager)context.getSystemService(Context.LOCATION_SERVICE);

        //Start gps to get our location  
        this.locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, UPDATE_FREQ, this);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        kill();
    }

    @Override
    public IBinder onBind(Intent arg0) {
        return mBinder;
    } 

    private final IBinder mBinder = new MyBinder();

    public class MyBinder extends Binder {
        public LocationMonitor getService() {
            return LocationMonitor.this;
        }
    }
}

请您帮我克服这个问题?
先谢谢了。

Would you please help me to get over this issue? Thanks in advance.

推荐答案

与原来的Galaxy S手机,GS2的GPS工作正常。

Unlike the original Galaxy S phone, the GS2's GPS works okay.

从$ C $来看c您正在使用getLastKnownLocation并回落至粗,当GPS不可用。因此,我认为这只是发生的事情:
  - 你得到或者是非常过时的GPS定位
  - 或粗略的位置和谷歌不那么它的关闭区域地图非常好

Judging from your code you're using getLastKnownLocation and falling back to Coarse when GPS is not available. So I think that's just what's happening: - you're getting either a very outdated GPS location - or a coarse location and Google doesn't map your area very well so it's off.

您可以通过添加日志或通过检查供应商,并正在从getLastKnownLocation()获取非空位置对象的时间戳检查这些假设。

You can check these assumptions by adding logs or by checking the provider and the timestamp of the non-null location object you are getting from getLastKnownLocation().

这篇关于三星Galaxy2不正确的GPS定位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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