0
我有這個問題我沒有看到代碼中的任何錯誤,但getLastKnownLocation每次都返回null。有任何想法嗎 ?Android lastKnownLocation返回null
public class LocationDemo2Activity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
EditText et1 = (EditText) findViewById(R.id.editText1);
LocationManager manager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
Location location = manager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if(location != null) et1.setText((int)location.getLatitude());
else et1.setText("null");
}
}
感謝
我該如何找到位置?我可以強制操作系統使用GPS或網絡或Wifi來查找當前位置 – 2013-10-30 12:23:45
我如何programmaticaly打開谷歌位置服務我試過這個http://stackoverflow.com/questions/4721449/enable-gps-programatically- like-tasker/5305835#5305835但它不工作我需要它在2.3.3 gingebread – 2013-10-30 12:29:22
@ user2726456:使用requestLocationUpdates()來請求位置更新。 – CommonsWare