你好我有應用程序每5秒詢問一次GPS位置,但它總是返回相同的位置。我嘗試過DDMS中的替代位置或通過telnet(地理修復......) 但不管怎樣,它都返回初始位置。 什麼錯了?Android模擬器代替GPS位置
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);
}
}
Thx for answer。我已經嘗試根據熟悉的教程製作應用程序(使用requestLocationUpdates)。但問題是一樣的。當我嘗試將GPS位置替換爲模擬器時,它只能使用一次。我試圖改變位置很多次,但位置沒有改變。我不知道什麼是錯的。 :/ – Tom 2010-10-02 18:33:22