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