[英]Fused Location Provider in Android
我正在使用Fused Location Provider開發應用程序。 我有個疑問。 為了定期獲取位置,它使用requestLocationUpdates()。 但是從哪個來源獲取WIFI或GPS或網絡的位置。 在我的應用程序中,僅當WiFi處於開啟狀態時,它才會定期獲取位置。 當WiFi處於關閉狀態時,它無法獲得該位置(它應該從GPS或網絡的其他來源獲得位置。但它永遠不會獲得位置。或者我必須為GPS和網絡編寫聽眾)。 我不知道是什么問題。 誰能幫我。
並且,它是否僅適用於所有提供商(Wifi,GPS,網絡)或其他。
public void checkPlay(){
int resp = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
if (resp == ConnectionResult.SUCCESS) {
locationClient = new LocationClient(this, this, this);
locationClient.connect();
} else {
Toast.makeText(this, "Google Play Service Error " + resp,
Toast.LENGTH_LONG).show();
}
}
public void onConnected(Bundle arg0) {
// TODO Auto-generated method stub
if (locationClient != null && locationClient.isConnected()) {
locationRequest = LocationRequest.create();
locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
locationRequest.setInterval(100);
locationClient.requestLocationUpdates(locationRequest, this);
}
}
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
try {
if (location != null) {
lat = location.getLatitude();
long = location.getLongitude();
}
} catch (Exception e) {
Log.d(Fots.TAG,
"GpsTrackService.mGpsLocationListener.onLocationChanged", e);
}
}
Fused API提供3個位置提供程序。
HIGH_ACCURACY模式使用所有位置提供商,但是,它優先考慮位置提供商,並包括GPS和位置提供商。 定位精度大約在10米范圍內。
BALANCED_POWER模式將GPS排除在其位置提供商列表之外,並使用其他提供商,包括手機信號塔,wifi等。在這種情況下,位置精度約為40米。
NO_POWER不使用任何位置提供程序,而是從其他應用程序獲取位置的被動模式。 准確度可能是一英里或更長。 它完全基於最近由其他應用程序獲取的位置。
如果您在示例中使用PRIORITY_HIGH_ACCURACY,它將使用所有可用的源(wifi,單元格,gps和內部傳感器)。 如果你關閉wifi並且在室內,你可能無法獲得gps鎖定(通常gps在室內不起作用,除非在某些區域,當你靠近窗戶時)。 如果wifi,單元格和gps不可用(因為它們在設置中關閉或者在您的特定位置不可用),它將不會返回位置(僅內部傳感器不足以創建從頭開始的位置)。
如果你在室內,GPS可能無法正常工作。 所以它將回歸到wifi /三角測量。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.