我有以下代码:
LocationManager mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
LocationListener mlocListener = new MyLocationListener();
mlocManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 0, 0, mlocListener);
和MyLocationListener
类:
public class MyLocationListener implements LocationListener{
@Override
public void onLocationChanged(Location loc){
loc.getLatitude();
loc.getLongitude();
tv_GPSlat.setText("Latitude: " + loc.getLatitude());
tv_GPSlon.setText("Longitude: " + loc.getLongitude());
}
@Override
public void onProviderDisabled(String provider){
Toast.makeText( getApplicationContext(),"GPS is not working", Toast.LENGTH_SHORT ).show();
}
@Override
public void onProviderEnabled(String provider){
Toast.makeText( getApplicationContext(),"GPS is working",Toast.LENGTH_SHORT).show();
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras){
}
}
我想将当前的经度和纬度保存到我TextView
的 s ( tv_GPSlat
, tv_GPSlon
) 但位置值不是恒定的(它们一直在变化)。我怎样才能做到这一点?