【问题标题】:FusedLocationService not aquiring GPS signal in AndroidFusedLocationService 在 Android 中未获取 GPS 信号
【发布时间】:2014-03-03 19:50:35
【问题描述】:

我正在使用新的 FusedLocationService,但是,尽管我在室内得到纬度和经度,但我没有看到 GPS 信号被获取(通知栏中的小 GPS 点没有出现)。

我正在使用来自here 的示例,适用于定位服务

我不明白的是为什么尽管启用了 GPS,但没有搜索 GPS 信号(但我正在获取坐标,我想我是从 wifi 或小区 ID 获取的)

在我的应用程序类中,我创建了一个服务(这是一个 ServicesManager,它又创建了另一个服务(用于检索位置)。我将作为上下文发送到 LocationClient 的 ServicesManager,因为它是一个上下文(因为它是一个服务) .

提前致谢。吉列尔莫。

更新 如果我在启用 GPS 的情况下关闭手机定位服务中的使用无线网络选项,我根本无法获得位置信息。因此,FusedLocationService 和 GPS 发生了一些变化。

我将添加代码以便更好地理解

Application 类中,我使用来自以下位置的 LocalService 示例:here

private ServicesManager mBoundService;
    private boolean mIsBound;

    private ServiceConnection mConnectionToServicesManager = new ServiceConnection() {

        public void onServiceConnected(ComponentName className, IBinder service) {
            mBoundService = ((ServicesManager.LocalBinder)service).getService();

    servicesManager = mBoundService;
        }

        public void onServiceDisconnected(ComponentName className) {
            mBoundService = null;
        }
    };

    void doBindServiceManagerService() {
        bindService(new Intent(this, ServicesManager.class), mConnectionToServicesManager, Context.BIND_AUTO_CREATE);
        mIsBound = true;
    }

    void doUnbindService() {
        if (mIsBound) {
            unbindService(mConnectionToServicesManager);
            mIsBound = false;
        }
    }

然后 ServicesManager 扩展 Service 并且在构造函数中我正在写这个:

fusedLocationService = new FusedLocationService(this);

然后我打电话给:

fusedLocationService.startListeningLocationUpdates(this);

这是FusedLocationService类中startListeningLocationUpdates的实现

public boolean startListeningLocationUpdates(Context context) {
    if (!GdpTesisApplication.IsGooglePlayServicesAvailable) {
        return false;
    }

    mDetectionRequester.requestUpdates();
    FusedLocationService.IsServiceRunning  = true;
    return true;
}

并且 requestUpdates() 尝试连接到 GooglePlayServices

private void requestConnection() {
    getFusedLocationClient().connect();
}

@Override
public void onConnected(Bundle arg0) {
    continueRequestLocationUpdates();
}

private void continueRequestLocationUpdates() {
    locationrequest = LocationRequest.create();
    locationrequest.setInterval(LocationUtils.DETECTION_INTERVAL_MILLISECONDS);

    getFusedLocationClient().requestLocationUpdates(locationrequest, createRequestPendingIntent());
}

private PendingIntent createRequestPendingIntent() {
    if (null != getRequestPendingIntent()) {
        return mFusedLocationPendingIntent;
    } else {
        Intent intent = new Intent(mContext, FusedLocationIntentService.class);
        PendingIntent pendingIntent = PendingIntent.getService(mContext, 1, intent, PendingIntent.FLAG_UPDATE_CURRENT);
        setRequestPendingIntent(pendingIntent);
        return pendingIntent;
    }
}

最后我有一个 IntentService ,它 onHandleIntent 提取位置并显示它:

Location location = intent.getParcelableExtra(LocationClient.KEY_LOCATION_CHANGED);

我不知道为什么 GPS 不工作。有什么想法吗?

【问题讨论】:

    标签: android location


    【解决方案1】:

    看这里:

    http://developer.android.com/reference/com/google/android/gms/location/LocationRequest.html#setPriority%28int%29

    您没有为 LocationRequest 设置优先级。试试 PRIORITY_HIGH_ACCURACY。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-30
      • 1970-01-01
      相关资源
      最近更新 更多