我已经完成了这段代码,我要求更新位置。我想知道我是否正确实现了它。打开页面后,我请求更新(通过 gps 优先选择网络)...并在函数 onlocationchanged 中显示位置。我想问一下,当我做getlastknownlocation时,是否有可能在onlocationchanged中得到类似的位置空值?我停止使用 ghetlastknownlocation,因为它有时会返回 nulll 和错误的值。
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); }