2017-03-04 66 views
1

我從LocationListener獲得了這個值,但是這個代碼只給了4或5位數字,比如43.1234,我想要更高的精度,比如43.1234567,那麼該怎麼做呢?android如何獲得7位或更多數字的當前位置精度

private LocationListener mLocationListener = new LocationListener() { 
    @Override 
    public synchronized void onLocationChanged(Location l) { 
     strLatLng = l.getLatitude() + "," + l.getLongitude(); 

    } 

    @Override 
    public void onProviderDisabled(String provider) { 
    } 

    @Override 
    public void onProviderEnabled(String provider) { 
    } 

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

}; 

這不是重要的,如果有另一種方式,而不是在LocationListener的,我得到這個精度就在我寫一篇關於谷歌地圖setOnMapClickListener。像這樣: 還有嗎?

googleMap.setOnMapClickListener(new GoogleMap.OnMapClickListener() { 
     public void onMapClick(LatLng CLICKED_LOC) { 
      double lx,ly; 
      lx = CLICKED_LOC.latitude; 
      ly = CLICKED_LOC.longitude; 
      strLatLng = lx+","+ly; 
     } 
    }); 

回答

4

有3種類型Android中的位置信息提供的:

  1. GPS_PROVIDER
  2. NETWORK_PROVIDER
  3. PASSIVE_PROVIDER。

用途: locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,5000,10,新MyLocationListener());

您將獲得精度高達14+小數位。

但是如果你使用它們的融合是這樣的:

LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient,mLocationRequest,my_google_listener);

您將精確到6到7位小數。嘗試一下 !!!裁判

但這裏要注意的幾件事情是,GPS提供商需要時間,而谷歌的位置要快得多,因爲它從API調用到其谷歌服務器的數據庫中獲取的數據來獲取位置。

當谷歌提供商通過移動或wifi數據獲取位置時,GPS離線工作。

+0

感謝,GPS心情太慢,屋頂下是沒有作用可言,比我在地圖上沒有選擇,強制用戶水龍頭超過得到他/她的確切位置10位數字。 –

+1

要獲得更準確的位置,您應該嘗試使用Fuse位置提供商。 – TwinkalGajera

+0

我使用融合,但沒有得到我想要的精度,它顯示約5米錯誤 –

1

我從LocationListener中得到了這個,但是這個代碼只給了4或5位數字,比如43.1234,我想要43.1234567更精確,所以怎麼做?

首先,我不認爲數字計數會影響準確性準確。您應該依靠位置的準確性值來代替。例如,locationX(位數小於6,準確度8)比位置Y(位數大於6,準確度10)可靠。

其次,GPS會給你更準確的位置,但我強烈建議使用融合位置提供商。因爲它結合了一些因素的引擎蓋下,和你的願望(如PRIORITY_HIGH_ACCURACY)

再次產生最好的位置,我看到你的評論,「我在地圖上沒有選擇,強制用戶點擊來獲得他/她的確切位置超過10位數「。我不知道你的應用場景,但這聽起來有點大。我建議閱讀這個答案,https://gis.stackexchange.com/a/109178/77725

// https://gis.stackexchange.com/a/109178/77725 
Decimal Places Aprox. Distance Say What? 
1    10 kilometers  6.2 miles 
2    1 kilometer  0.62 miles 
3    100 meters   About 328 feet 
4    10 meters   About 33 feet 
5    1 meter   About 3 feet 
6    10 centimeters  About 4 inches 
7    1.0 centimeter  About ½ an inch 
8    1.0 millimeter  The width of paperclip wire. 
9    0.1 millimeter  The width of a strand of hair. 
10    10 microns   A speck of pollen. 
11    1.0 micron   A piece of cigarette smoke. 
12    0.1 micron   You're doing virus-level mapping at this point. 
13    10 nanometers  Does it matter how big this is? 
14    1.0 nanometer  Your fingernail grows about this far in one second. 
15    0.1 nanometer  An atom. An atom! What are you mapping?