Android:从DDMS重复错误的值

时间:2012-03-27 10:37:07

标签: android logcat ddms

我想从DDMS接收浮点值,但它会发送一个整数 例: 经度:2.351696 纬度:48.857593

但我收到了 经度: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);

    }

日志:

03-27 09:25:20.163:I /纬度(793):48.0 03-27 09:25:20.163:我/经度(793):2.0

private double getDistanceBetweenPoints(double lat1,double long2,double arrival_lat,double arrival_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;
}

1 个答案:

答案 0 :(得分:1)

在模拟器中运行是一个问题。您的电脑没有GPS芯片,因此您无法获得非常准确的坐标。

有关如何模拟准确地理位置的详细信息和帮助: http://developer.android.com/guide/topics/location/obtaining-user-location.html

之前在stackoverflow上讨论.... GPS accuracy of Android Emulator