簡體   English   中英

如何通過GPS_PROVIDER獲得更高的精度

[英]How to get more accuracy by GPS_PROVIDER

我要獲得非常高的准確性是一項艱巨的任務。 所以我正在使用GPS_PROVIDER。 但是我的代碼准確性不正確 一段時間后,它顯示我距當前位置10至50米 有時它顯示我與當前位置的距離為5至15米 我已經測試過XOLO和Sony這兩種設備。 我已經解決了這些問題,無法解決。 這是我的代碼:

@Override
protected void onResume() {
    super.onResume();

    if(mMap!= null)
        mMaprivate LatLng geo;
map.clear();

    locationManager = (LocationManager)this.getSystemService(Context.LOCATION_SERVICE);             
    mFragment = (SupportMapFragment) this.getSupportFragmentManager().findFragmentById(R.id.map);
    mMap = mFragment.getMap(); 
    }
   setListener();
 }

private void setListener() {    
    System.out.println("setListener()  locationListener = "+locationListener);
    if(locationListener != null){
        clearListener();
    }

    Toast toast = Toast.makeText(this, this.getResources().getString(R.string.maps_loading), Toast.LENGTH_LONG);
    toast.show();   
    private LatLng geo;

    locationListener = new CustomLocationListener();

    Criteria criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    //criteria.setAccuracy(Criteria.ACCURACY_HIGH);
    criteria.setPowerRequirement(Criteria.NO_REQUIREMENT);
    String bestProvider = locationManager.getBestProvider(criteria, true); 
    Toast.makeText(this, "bestProvider= "+bestProvider, Toast.LENGTH_SHORT).show();
//  locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
   locationManager.requestLocationUpdates(bestProvider, 0, 0, locationListener);

    handler=new Handler();
    timeoutTask = new TimeoutTask(locationListener);
    handler.postDelayed(timeoutTask, 50*1000);
}

private void clearListener(){
    if(locationListener != null){
        locationManager.removeUpdates(locationListener);
        locationListener = null;
    }
}

private void gotLocation(Location location){
    loc = location;
    System.out.println("getLocation = "+location.getLatitude());
 //   Toast.makeText(getBaseContext(), "new Lat = "+location.getLatitude(), Toast.LENGTH_LONG).show();
}

public class CustomLocationListener implements LocationListener {
    private boolean isCompleted = false;

    public CustomLocationListener() {}

    @Override
    public void onLocationChanged(Location location) {
        isCompleted=true;

        System.out.println("onLocationChanged 1");

          // Called when a new location is found by the GPS location provider.
          if(isBetterLocation(location, loc)){
            //  Toast.makeText(getBaseContext(), "yes", Toast.LENGTH_LONG).show();
              System.out.println("onLocationChanged 2");
              gotLocation(location);
          }
          System.out.println("onLocationChanged 3");
          clearListener();
          setUserPoint();
    }

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

    @Override
    public void onProviderEnabled(String provider) { }

    @Override
    public void onProviderDisabled(String provider) { }

    public boolean isCompleted() {
        return isCompleted;
    }private LatLng geo;

}   
private LatLng geo;

 public class TimeoutTask implements Runnable {

    private CustomLocationListener listener;

    public TimeoutTask(CustomLocationListener listener) {
        this.listener=listener;
    }

    @Override
    public void run() {
        // TODO Auto-generated method stub
        if (listener == null || listener.isCompleted()) {
            Log.e("provider", "completed");
       }
        else {
            Toast.makeText(ScorecardMapViewActivity.this, "We were unable to find your position, please try again", Toast.LENGTH_LONG).show();
            Log.e("provider", "timeout");
            clearListener();
            setUserPoint();
            if(goToScorecardStep3WithLocation) finish(); 
        }
    }
}



protected boolean isBetterLocation(Location location, Location currentBestLocation) {
    if (currentBestLocation == null) {
        // A new location is always better than no location
        return true;
    }

    // Check whether the new location fix is newer or older
    long timeDelta = location.getTime() - currentBestLocation.getTime();
    boolean isSignificantlyNewer = timeDelta > TWO_MINUTES;
    boolean isSignificantlyOlder = timeDelta < -TWO_MINUTES;
    boolean isNewer = timeDelta > 0;

    // If it's been more than two minutes since the current location, use the new location
    // because the user has likely moved
    if (isSignificantlyNewer) {
        return true;
    // If the new location is more than two minutes older, it must be worse
    } else if (isSignificantlyOlder) {
        return false;
    }

    // Check whether the new location fix is more or less accurate
    int accuracyDelta = (int) (location.getAccuracy() - currentBestLocation.getAccuracy());
    boolean isLessAccurate = accuracyDelta > 0;
    boolean isMoreAccurate = accuracyDelta < 0;
    boolean isSignificantlyLessAccurate = accuracyDelta > 200;

    // Check if the old and new location are from the same provider
    boolean isFromSameProvider = isSameProvider(location.getProvider(),
            currentBestLocation.getProvider());

    // Determine location quality using a combination of timeliness and accuracy
    if (isMoreAccurate) {
        return true;
    } else if (isNewer && !isLessAccurate) {
        return true;
    } else if (isNewer && !isSignificantlyLessAccurate && isFromSameProvider) {
        return true;
    }
    return false;
}

private LatLng geo;

private void setUserPoint() {
    if(!goToScorecardStep3WithLocation) {
    if(loc != null) {

         if(handler != null) { System.out.println("removed timeout task from handler");
            handler.removeCallbacks(timeoutTask); }

        geo = HelperUtil.getLatLng(loc);
        mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(geo, 18));
        mMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);

        System.out.println("loc.getLatitude() = "+loc.getLatitude());
        System.out.println("loc.getLongitude() = "+loc.getLongitude());

        // your current position show.
         mMap.addMarker(new MarkerOptions().title("Player").position(geo)
        .icon(BitmapDescriptorFactory.fromResource(R.drawable.map_point)));
}
}
}

請任何一位專家幫助我。 您的幫助將非常有幫助。 謝謝!

更新:-

我注意到我是否在同一地方。 有時我會得到長小數點,有時會得到小小數點。 小數點后的距離也有影響嗎? 我正在計算院子里的距離。

當前位置= 緯度28.65361000000004長= 77.4122733333333

先前的當前位置點(此位置相同,但經/緯度不同)

緯度= 28.653685000000003緯度 = 77.4123083333334

我有8碼的距離。 我認為某些問題可能是由於數字長或小。 有沒有辦法讓我們只能得到長的小數點?

消費類GPS接收機在95%的情況下具有2.5-6m的精度,您無法提高移動設備的精度。

如果您靜止不動(通過告訴用戶停止狀態和停止狀態的用戶交互),則可以計算平均位置。
尤其是當靜止不動時,GPS芯片的精度較低,因為多普勒頻移只能在移動時使用。

要計算設備的精度,您應該采取一些措施,計算平均位置,並為每個度量計算到該平均位置的距離。 然后,該值應在3-6m之間。

您寫道,您希望靜止不動時兩個位置之間的距離為0m。
但這不適用於GPS。 由於對流層的波動條件,信號延遲略有變化,導致靜止時跳躍位置。

如果啟用了靜態過濾器(iOS默認使用該過濾器),則只會得到0m。 Android中也應該啟用這種過濾器(例如,通過將距離閾值設置為大於0的值)。

OnLocation方法中,檢查位置精度是否不合適,通常,下一次調用OnLocation會更准確。 更高的精度需要更多的工作。 您已經看到Google地圖在該位置周圍顯示一個圓圈,並且可能會看到它的尺寸減小了。 圓的半徑是基於位置精度的,這是Location的屬性。

下面的方法很好用。 我在開車,騎自行車,walking狗和在Harley上進行了廣泛的測試。 它過濾掉Mcd進入的位置,並把位置設在德克薩斯州,那里是Mcd的wifi提供商所基於的地方,而那些討厭的地方有1億個位置。

@Override
public void onLocationChanged(Location location) {


    if (!location.hasAccuracy()) {
            return;
        }
        if (location.getAccuracy() > myDesiredAccuracy) {
            return;
        }

//blah what your app does...

    isCompleted=true;

    System.out.println("onLocationChanged 1");

      // Called when a new location is found by the GPS location provider.
      if(isBetterLocation(location, loc)){
        //  Toast.makeText(getBaseContext(), "yes", Toast.LENGTH_LONG).show();
          System.out.println("onLocationChanged 2");
          gotLocation(location);
      }
      System.out.println("onLocationChanged 3");
      clearListener();
      setUserPoint();
}

注意:有時候您會陷入無法獲得良好GPS接收的死角。 這些是由於在建築物內,電力線,視線,高速公路切開,建築物中未映射的wifi,其他發射干擾GPS衛星接收的無線電信號的設備引起的。 基本上任何會干擾無線電接收的東西都會干擾GPS。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM