大佬教程收集整理的这篇文章主要介绍了Android LocationManager标准,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
如果GPS提供商不可用或没有位置(卫星可见性差)我会从网络提供商处获得GPS提供商的位置.
是否有可能根据我的需要选择使用标准?
在其代码中,如果您使用两个提供商(来自GPS和网络),它将进行比较:
... } else if (mUseBoth) { // Get coarse and fine LOCATIOn updates. mFineProviderButton.setBACkgroundresource(R.drawable.button_inactivE); mBothProviderButton.setBACkgroundresource(R.drawable.button_activE); // request updates from both fine (gps) and coarse (network) providers. gpsLOCATIOn = requestupdatesFromProvider( LOCATIOnManager.GPS_PROVIDER,R.String.not_support_gps); networkLOCATIOn = requestupdatesFromProvider( LOCATIOnManager.NETWORK_PROVIDER,R.String.not_support_network); // If both providers return last kNown LOCATIOns,compare the two and use the better // one to update the UI. If only one provider returns a LOCATIOn,use it. if (gpsLOCATIOn != null && networkLOCATIOn != null) { updateUILOCATIOn(getBetterLOCATIOn(gpsLOCATIOn,networkLOCATIOn)); } else if (gpsLOCATIOn != null) { updateUILOCATIOn(gpsLOCATIOn); } else if (networkLOCATIOn != null) { updateUILOCATIOn(networkLOCATIOn); } } ...
它实现了最佳位置提供者的想法(通过确定在指定时间段内的准确性,如:
/** Determines whether one LOCATIOn reading is better than the current LOCATIOn fix. * Code taken from * http://developer.android.com/guide/topics/LOCATIOn/obtaining-user-LOCATIOn.html * * @param newLOCATIOn The new LOCATIOn that you want to evaluate * @param currentBestLOCATIOn The current LOCATIOn fix,to which you want to compare the new * one * @return The better LOCATIOn object based on recency and accuracy. */ protected LOCATIOn getBetterLOCATIOn(LOCATIOn newLOCATIOn,LOCATIOn currentBestLOCATIOn) { if (currentBestLOCATIOn == null) { // A new LOCATIOn is always better than no LOCATIOn return newLOCATIOn; } // check whether the new LOCATIOn fix is newer or older long timedelta = newLOCATIOn.getTime() - currentBestLOCATIOn.getTime(); @R_874_8487@an isSignificantlyNewer = timedelta > TWO_minutES; @R_874_8487@an isSignificantlyOlder = timedelta < -TWO_minutES; @R_874_8487@an isNewer = timedelta > 0; // If it's been more than two minutes since the current LOCATIOn,use the new LOCATIOn // because the user has likely moved. if (isSignificantlyNewer) { return newLOCATIOn; // If the new LOCATIOn is more than two minutes older,it must be worse } else if (isSignificantlyOlder) { return currentBestLOCATIOn; } // check whether the new LOCATIOn fix is more or less accurate int accuracyDelta = (int) (newLOCATIOn.getAccuracy() - currentBestLOCATIOn.getAccuracy()); @R_874_8487@an isLessAccurate = accuracyDelta > 0; @R_874_8487@an isMoreAccurate = accuracyDelta < 0; @R_874_8487@an isSignificantlyLessAccurate = accuracyDelta > 200; // check if the old and new LOCATIOn are from the same provider @R_874_8487@an isFromSameProvider = isSameProvider(newLOCATIOn.getProvider(),currentBestLOCATIOn.getProvider()); // Determine LOCATIOn quality using a combination of timeliness and accuracy if (isMoreAccuratE) { return newLOCATIOn; } else if (isNewer && !isLessAccuratE) { return newLOCATIOn; } else if (isNewer && !isSignificantlyLessAccurate && isFromSameProvider) { return newLOCATIOn; } return currentBestLOCATIOn; }
以上是大佬教程为你收集整理的Android LocationManager标准全部内容,希望文章能够帮你解决Android LocationManager标准所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。