Android 中的融合位置提供程序 [英] Fused Location Provider in Android

查看:33
本文介绍了Android 中的融合位置提供程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Fused Location Provider 开发应用程序.我有个疑问.为了定期获取位置,它使用 requestLocationUpdates().但它从哪个来源获取位置,无论是从 WIFI 还是 GPS 或网络.在我的应用程序中,只有当 WiFi 开启时,它才会定期获取位置.当 WiFi 处于关闭状态时,它无法获取位置(它应该从 GPS 或网络的其他来源获取位置.但它永远不会获取位置.或者我必须为 GPS 和网络编写侦听器).我不知道是什么问题.谁能帮帮我.

I am developing an app using Fused Location Provider. I have a doubt. For getting location in regular intervals it uses requestLocationUpdates(). But from which source is it get the location either from WIFI or GPS or Network. In my app, it gets location in regular intervals only when WiFi is ON. When WiFi is in OFF state, then it can't get the location(it supposed to get location from some other source either form GPS or Network. But it never get location. Or i have to write listeners for GPS and Network). I don't know what is the problem. Can anyone help me.

而且,它是否仅在所有提供商(Wifi、GPS、网络)可用时才有效.

And, whether it works only when all the providers(Wifi,GPS,Network) available or else.

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 个位置提供者.

Fused API provides 3 location providers.

  1. 高准确度
  2. BALANCED_POWER
  3. NO_POWER

HIGH_ACCURACY 模式使用所有位置提供程序,但是,它优先考虑位置提供程序并包括 GPS 和位置提供程序.定位精度大约在 10 米范围内.

The HIGH_ACCURACY mode use all location providers, However, it prioritize the location providers and include GPS along with location providers. The location accuracy is approximately within 10 meters of range.

BALANCED_POWER 模式在其位置提供者列表中排除 GPS,并使用其他提供者,包括基站、wifi 等.在这种情况下,位置精度约为 40 米.

The BALANCED_POWER mode exclude GPS for its list of location providers, and use the other providers based including cell towers, wifi etc. In this case, the location accuracy is approximately 40 meters.

NO_POWER 不使用任何位置提供程序,而是从其他应用程序获取位置的被动模式.准确度可能是一英里或更多.它仅基于其他应用程序最近获取的位置.

The NO_POWER do not use any location provider, instead it is a passive mode of getting location from other apps. The accuracy could be a mile or more. It is solely based on the locations that are fetch by other applications recently.

这篇关于Android 中的融合位置提供程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆