我已經定義了一種通過按下按鈕來獲取當前位置的方法,當我第一次按下它時,它已經起作用了。但是它沒有任何回報給我。而沒有異常拋出我無法通過GPS在我的模擬器中獲取緯度和經度
public class getLoc extends Activity{
private Button btn;
private TextView tv;
private LocationManager locm;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tv=(TextView) findViewById(R.id.location_text);
btn=(Button) findViewById(R.id.btn_location);
btn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
locm=(LocationManager) getLoc.this.getSystemService(Context.LOCATION_SERVICE);
locm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, new myLocationListener());
}
});
}
protected void getCurrentLocation(){
Location loc=locm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
Toast.makeText(getApplication(), String.valueOf(loc.getLatitude()), Toast.LENGTH_SHORT).show();
System.out.println(loc.getLatitude());
System.out.println(loc.getLongitude());
爲什麼你想它在模擬器?嘗試在真實的設備上。 – Lucifer 2012-01-12 03:36:01
該代碼是否正常?我只有一個ZTE_U880.it的移動設備需要很長時間才能獲取位置信息。 – lanyimo 2012-01-12 03:39:58
是的,代碼是好的,對不起,遲交回復 – Lucifer 2012-01-12 04:19:00