0

我有一个文本视图来显示我的纬度和经度,现在问题是我总是得到这对夫妇(32,35)(我认为这是在某个海洋的某个地方),我什至出去散步给 gps机会,但我一无所获。

我想看看它是否与我的手机或手机中的 gps 有关,所以我继续打开 Waze 应用程序,发现它确实有效。

可能是什么问题?

这是我的简单代码片段:

public class Main extends Activity implements LocationListener {
    private LocationManager manager;
    private TextView tv;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        tv = (TextView) findViewById(R.id.textView1);
        tv.setText("Hello There");
        manager = (LocationManager) this.getSystemService(LOCATION_SERVICE);
        manager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);

    }

    @Override
    public void onLocationChanged(Location location) {
        tv.setText((int)location.getLatitude()+ ","+ (int)location.getLongitude());
    }
...
}
4

1 回答 1

1

尝试这个

tv.setText(location.getLatitude()+ ","+location.getLongitude());

代替

tv.setText((int)location.getLatitude()+ ","+ (int)location.getLongitude());
            ^^^                               ^^^   

因为您正在转换latitude,并且longitudeint您的情况下,您可能会得到微小的变化。

喜欢

32.110 35.500  you will get (32,35)
32.120 35.540  you will get (32,35)
32.180 35.580  you will get (32,35)
32.200 35.900  you will get (32,35)
32.290 35.880  you will get (32,35)
   ^^^    ^^^
于 2012-08-16T10:20:43.780 回答