我正在尝试制作一个简单的Android应用程序来确定GPS的当前位置,但是当我在手机上运行应用程序时,它只是给了我准确性而没有给出真实的坐标这里是我的代码
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
v1 = (TextView) findViewById(R.id.textView1);
v2 = (TextView) findViewById(R.id.textView1);
v3 = (TextView) findViewById(R.id.textView1);
int GpsUpdateInterval = 60 * 1000;
int GpsUpdateRadius = 15;
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
GpsUpdateInterval, GpsUpdateRadius, new LocationListener() {
@Override
public void onStatusChanged(String provider, int status,
Bundle exras) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onProviderDisabled(String provider) {
}
@Override
public void onLocationChanged(Location location) {
// this function trigger when a new location founded
v1.setText("Lat "
+ String.valueOf(location.getLatitude()));
v2.setText("Lng "
+ String.valueOf(location.getLongitude()));
v3.setText("Accurcy "
+ String.valueOf(location.getAccuracy()));
}
});
}
答案 0 :(得分:1)
v1 = (TextView) findViewById(R.id.textView1);
v2 = (TextView) findViewById(R.id.textView1);
v3 = (TextView) findViewById(R.id.textView1);
你的视图绑定不好;)