Hello i have app which ask every 5second for GPS position but it allways returns same position. I have tried substitite position in DDMS or by telnet (geo fix ... ...) But allway it return initial postion. Whats wrong?
public class App09_GPS_RepeatedAsking extends Activity {
TextView tv1;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tv1 = (TextView) findViewById(R.id.textview);
Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
Handler mHandler = new Handler();
@Override
public void run() {
try{
mHandler.post(new Runnable(){
@Override
public void run() {
LocationManager lm = (LocationManager)getSystemService(LOCATION_SERVICE);
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
criteria.setAltitudeRequired(false);
criteria.setBearingRequired(false);
criteria.setCostAllowed(true);
criteria.setPowerRequirement(Criteria.POWER_LOW);
String provider =lm.getBestProvider(criteria, false);
//Location loc = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
Location loc = lm.getLastKnownLocation(provider);
String Text = "My current location is: " + "Latitud = " + loc.getLatitude() + " Longitud = " + loc.getLongitude();
Toast.makeText( getApplicationContext(), Text, Toast.LENGTH_SHORT).show();
Log.v("LOG",Text);
}
);
}catch(Exception e){
Log.v("LOG",e.toString());
}
}
}, 0, 5000);
}
}