在Android的融合位置提供者 [英] Fused Location Provider in Android

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

问题描述

我正在开发使用熔融位置提供一个应用程序。我有一个疑问。对于定期获得的位置,它使用requestLocationUpdates()。但是,从哪个源是它无论是从WIFI和GPS或网络上获取的位置。在我的应用程序,它得到定期的位置,只有当WiFi是ON。当无线网络处于关断状态,那么就不能得到的位置(它应该从其他来源任何形式的GPS或网络获取位置。但它从来没有得到的位置。或者我必须写监听GPS和网络)。我不知道是什么问题。谁能帮我。

和,无论是它的工作原理,只有当所有的供应商(WIFI,GPS,网络)提供否则后果不堪设想。

 公共无效checkPlay(){

  INT RESP = GooglePlayServicesUtil.isGooglePlayServicesAvailable(本);
    如果(RESP == ConnectionResult.SUCCESS){
        locationClient =新LocationClient(这,这,这一点);
        locationClient.connect();
    } 其他 {
        Toast.makeText(这一点,谷歌播放服务错误+ RESP,
                Toast.LENGTH_LONG).show();

    }
 }


公共无效onConnected(捆绑为arg0){
    // TODO自动生成方法存根


    如果(locationClient =空&安培;!&安培; locationClient.isConnected()){

        locationRequest = LocationRequest.create();
        locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
        locationRequest.setInterval(100);
        locationClient.requestLocationUpdates(locationRequest,这一点);

    }
}

        公共无效onLocationChanged(位置定位){
    // TODO自动生成方法存根
    尝试 {
        如果(位置!= NULL){
            纬度= location.getLatitude();
                            长= location.getLongitude();
        }
    }赶上(例外五){
        Log.d(Fots.TAG,
                GpsTrackService.mGpsLocationListener.onLocationChanged,E);

    }
}
 

解决方案

电熔API提供了3个位置提供。

  1. HIGH_ACCURACY
  2. BALANCED_POWER
  3. NO_POWER

在HIGH_ACCURACY模式中使用的所有位置的提供者,但是,它优先考虑的位置,供应商,包括全球定位系统与位置提供。定位精度约为10米之内的范围。

的BALANCED_POWER模式排除GPS进行位置提供的名单,并使用基于其他提供者,包括蜂窝塔,无线等。在这种情况下,位置精度大约为40米。

在NO_POWER不使用任何位置提供,取而代之的则是从其他应用程序获取位置的被动模式。精度可以是一英里或更长。它完全是基于属于由其他应用程序取最近的位置。

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.

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 provides 3 location providers.

  1. HIGH_ACCURACY
  2. BALANCED_POWER
  3. NO_POWER

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.

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.

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天全站免登陆