0

我已经使用GoogleApiClient来获取位置信息。我的要求是找到准确的位置信息。

在位置请求中,我将优先级设置为 PRIORITY_HIGH_ACCURACY,然后当我在室内时,我在室内时没有得到任何位置更新。我需要返回位置对象,它可能是最后一个已知位置。

而且我也试过PRIORITY_LOW_POWER。但它从不使用 GPS 来获取位置信息。我认为使用它可能有点不准确。

我需要在室外使用 GPS 获得更好的位置信息,以及我在室内时要返回的最后一个已知位置信息。那么哪个优先级适合我呢?

而且总是得到高度和方位为0。总是得到融合的提供者。我认为 GoogleApiClient 不提供提供位置信息的提供者详细信息。

补充说明:

我有以下实现:

//Request for location update
LocationServices.FusedLocationApi.requestLocationUpdates(
                            mGoogleApiClient, mLocationrequest,
                            mLocationUpdatePendingIntent);


//Intent service where i receive the location information 
public LocationIntentService() {        
     super("LocationService");  
}
protected void onHandleIntent(Intent locationIntentObj) {
}


//Stop Location Update
LocationServices.FusedLocationApi.removeLocationUpdates(
                    mGoogleApiClient, mLocationUpdatePendingIntent);

就我而言,如何从 API 获取最后一个已知的位置信息。

请帮助我。

4

2 回答 2

3

[...] 然后,当我在室内时,我在室内时没有得到任何位置更新。[...] 而且总是将高度和方位设为 0。

您无法访问室内 GPS 卫星。这些值将由 GPS 提供。

我建议你使用方法setInterval(...)setFastestInterval(...). 你这样说:

我想要任何位置至少interval毫秒一次,但如果你有一个好位置,我可以每fastestInterval毫秒处理一次。

当 fused 在几毫秒内没有连接到 GPS 时,interval它应该在后台回退到网络提供商(同时应该从 Wi-Fi 获得准确的位置)。

FusedLocationProviderApi.getLastLocation(GoogleApiClient)欢迎您在设置重复收听之前使用方法。这将立即返回,但准确性可能会有所不同。

编辑:如果上述方法不起作用......在我的项目中,我一直在后台使用 fused provider 并具有平衡的电源优先级。然后我问额外的标准 GPS 提供商。

于 2014-12-08T14:32:57.190 回答
0

是的,我可以使用以下代码片段获取最后一个已知位置。

/**
 * Remove the user location update
 */
public void removeLocationUpdate() {
    if (mGoogleApiClient != null && mGoogleApiClient.isConnected()) {
        //Remove the location update
        LocationServices.FusedLocationApi.removeLocationUpdates(
                mGoogleApiClient, mLocationUpdatePendingIntent);
        //A status message updated to the UI
        mAppUtilInstance.broadcastStatusMessage(mContext,
                Constants.STATUS_MSG_116, Constants.STATUS_CODE_116);
    }
    if (Constants.locationInformationEntity == null) {
        //Getting the last known location
        Location mLocationIntentObject = LocationServices.FusedLocationApi
                .getLastLocation(mGoogleApiClient);
        if (mLocationIntentObject != null) {
            //Storing as entity 
            mAppUtilInstance.setLocationInformationEntity(mContext,
                    mLocationIntentObject);
        }
    }
}

当我删除位置更新时,我正在检查 api 是否在我在室内时提供位置信息。如果 API 无法提供,那么当位置请求被删除时,我将获取最后一个已知的位置信息。

希望这可以帮助其他在融合位置 api 中工作的人。

于 2014-12-09T07:52:08.633 回答