2011-10-25 31 views
0

林這段代碼用於獲取位置我的應用程序:如何在Android應用程序中獲得更準確的GPS讀數?使用

LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE); 
    lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000L, 200.0f, this); 

但是,當我在真正的Android手機嘗試應用它在actualy顯示該位置從位置IM約80公里。如何將我有這樣的代碼更準確。我希望得到的結果是什麼IM製作方法更準確..

即時通訊使用的onLocationChanged在地圖上顯示出來..這就是:

public void onLocationChanged(Location location) { 
    if (location != null) { 

     //Gets users longitude and latitude 
     lat = location.getLatitude(); 
     lng = location.getLongitude(); 

     //sets the GeoPoint usersLocation equal lat and lng 
     userLocation = new GeoPoint((int) lat * 1000000, (int) lng * 1000000); 

     OverlayItem usersLocationIcon = new OverlayItem(userLocation, null, null); 
     LocationPin myLocationPin = new LocationPin(userIcon, MainActivity.this); 

     //Removes the previous location 
     if(previousLocation != null) 
       mainMap.getOverlays().remove(previousLocation); 

     myLocationPin.getLocation(usersLocationIcon); 
     overlayList.add(myLocationPin); 

     //refresh the map 
     mainMap.invalidate(); 

     //Making myLocationPin into the previousLocation just to be able to remove it later 
     previousLocation = myLocationPin; 
    } 

回答

4

當來自GPS的位置與上次更新相差超過200.0米時,呼叫requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000L, 200.0f, this);要求每1000ms更新不超過一次。如果你想要更精確,請嘗試降低這些數字。

但是,你不應該錯過80公里。你是否在外面測試了天空的清晰視野?

我認爲這個問題與舍入有關。您正在使用new GeoPoint((int) lat * 1000000, (int) lng * 1000000);,而是這樣做:

new GeoPoint((int) (lat * 1e6), (int) (lng * 1e6)); 

不同的是,雙值乘法之前轉換爲整數。這樣,乘法就會發生,所以小數點後面的數字將被保留。

+0

天空的景色很明顯,我試圖將1000毫米降低到500毫米,將200米降低到50米..但它仍然顯示我距離真正的位置80公里。我還嘗試啓動Google地圖,顯示我的真實位置.. – Rakso

+0

你是如何在你的應用中顯示位置的?如果您記錄緯度和經度值,並將它們輸入Google地圖,那麼它會將您放到哪裏? – Craigy

+0

我使用谷歌地圖API來顯示這個經度和緯度。 – Rakso

0

有2個可能的答案...

您可以問精細的權限,這使用附近的Wi-Fi網絡,以便GPS一起得到你在哪裏更好的軌跡:

http://developer.android.com/reference/android/Manifest.permission.html#ACCESS_FINE_LOCATION

,或者你可能只是越來越糟糕GPS數據。您是否嘗試重新啓動手機?您是否在Google地圖中找到了正確的位置?

希望這會有所幫助。

+0

我在應用程序中使用了此權限..它在Google地圖中完美工作..但我看不到問題..是否有一些代碼可以添加以使其查找更準確的位置? – Rakso

+0

你得到哪些地點不準確?它們只是字符串值,還是顯示在您的應用程序中? – Codeman

相關問題