2012-03-27 60 views
0

錯誤的價值觀我希望收到DDMS一個浮點值,但它發送一個整數 例: 經度:2.351696 緯度:48.857593安卓:Recaive從DDMS

但我收到 經度:2.0 緯度:48.0

我該如何做這項工作?

的LocationManager LM =(的LocationManager)getSystemService(Context.LOCATION_SERVICE); lm.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,0,this);

} 


@Override 
public void onLocationChanged(Location location) { 
    latitude = location.getLatitude(); 
    longitude = location.getLongitude(); 
    if (location != null) { 
     Toast.makeText(this, "ma position :" + latitude + ", " + longitude, 
       Toast.LENGTH_LONG).show(); 
     Log.i("latitude", "" + latitude); 
     Log.i("longitude", "" + longitude); 

    } 

日誌:

9月3日至27日:25:20.163:I /緯度(793):48.0 9月3日至27日:25:20.163:I /經度(793):2.0

私人雙getDistanceBetweenPoints(雙LAT1,雙long2,雙arrive_lat,雙arrive_long){

int R = 6371; // km 

    double dLat = Math.toRadians(arrive_lat - lat1); 
    double dLon = Math.toRadians(arrive_long - long2); 

    double a = Math.sin(dLat/2) * Math.sin(dLat/2) 
      + Math.cos(Math.toRadians(lat1)) 
      * Math.cos(Math.toRadians(arrive_lat)) * Math.sin(dLon/2) 
      * Math.sin(dLon/2); 
    double c = 2 * Math.asin(Math.sqrt(a)); 
    double d = R * c; 

    return d*1000; 
} 
+0

DDMS是ADK調試監視器服務。你只是在Logcat輸出中看到Integer的? 如果是的話,請張貼被輸出消息 – 2012-03-27 10:52:13

+0

我使用這些值來計算2點GPS之間的距離和我有一個錯誤的結果,從而從DDMS值是錯誤的代碼。 – Wassim 2012-03-27 11:01:40

+0

'Location.getLatitude()'返回一個double,並且在logcat(48.0)中輸出一個double。我會調試你的應用程序,並在運行時檢查緯度和經度的值。 – 2012-03-27 11:02:40

回答

1

在模擬器中運行的問題在這裏。你的電腦沒有GPS芯片,所以你不會得到非常準確的座標。

欲瞭解更多信息和幫助如何嘲笑準確地緣位置: http://developer.android.com/guide/topics/location/obtaining-user-location.html

和之前的計算器討論.... GPS accuracy of Android Emulator

+0

Log.i( 「距離1」, 「」 + this.getDistanceBetweenPoints(48.857593,2.351696,48.864694,2.351922)); \t \t Log.i( 「距離2」, 「」 + this.getDistanceBetweenPoints(緯度,經度,48.864694,2.351922)); 當我使用靜態值時,第一個距離是真的,但是當我使用DDMS中的值時,第一個距離是錯的 – Wassim 2012-03-27 11:15:27

+0

您需要在您的getDistanceBetweenPoints()方法中發佈代碼,然後才能對其進行評論;) – 2012-03-27 11:18:17

+0

i post但在方法的代碼中沒有錯誤;問題是我如何可以接收來自DDMS不是整數:) – Wassim 2012-03-27 11:21:54