0
我已经完成了这个代码,我要求位置更新。我想知道我是否正确实施它。一旦打开页面,我要求更新(首选gps网络)......并且我在onlocationchanged函数中显示位置。我想问是否可以在onlocation改变我得到位置null类似,当我getlastknownknownlocation? 我停止使用ghetlastknownlocation,因为它有时会返回nulll和错误的值。Android网络提供商和GPS提供商处理
boolean isGPSEnabled = lm.isProviderEnabled(LocationManager.GPS_PROVIDER); boolean isNetworkEnabled = lm .isProviderEnabled(LocationManager.NETWORK_PROVIDER); if (!isGPSEnabled && !isNetworkEnabled) { ProgressBar progress = (ProgressBar)findViewById(R.id.progress); progress.setVisibility(View.INVISIBLE); Utilities.showAlertDialog2(RegionalStoresMeActivity.this, "", ""+getResources().getString(R.string.nothing_enabled), false); } else if(isNetworkEnabled){ // lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,0,0, this); lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,0,0, this); } else if(isGPSEnabled) { lm.requestLocationUpdates(LocationManager.GPS_PROVIDER,1,0, this); }
ok thx。不要onlocation改变我正在做locationmanager.removeupdates – user3278732
如果你做locationmanager.removeupdates,那么它会停止监听位置更新。 – kevz
我只需要一次,当它打开页面。 – user3278732