FusedLocationService在Android中未获取GPS信号
我正在使用新的FusedLocationService,但是,尽管我在室内获得了纬度和经度,但我没有看到GPS信号被获取(通知栏中的小GPS点没有出现) 我使用的是来自adapted to location service的示例 我不明白的是,尽管启用了GPS,但为什么没有搜索GPS信号(但我正在获取坐标,我想我是从wifi或手机id获取坐标的) 在我的应用程序类中,我创建了一个服务(这是一个ServicesManager,它又创建了另一个服务(用于检索位置)。我将ServicesManager作为上下文发送给LocationClient,因为它是一个服务 先谢谢你,吉勒莫 更新 如果在启用GPS的情况下关闭手机定位服务中的“使用无线网络”选项,则根本无法获取位置。因此,FusedLocationService和GPS出现了问题 我将添加代码,以便更好地理解它 在应用程序中类中,我使用的本地服务示例来自: 然后,ServicesManager扩展了服务,我在构造函数中写下:FusedLocationService在Android中未获取GPS信号,android,location,Android,Location,我正在使用新的FusedLocationService,但是,尽管我在室内获得了纬度和经度,但我没有看到GPS信号被获取(通知栏中的小GPS点没有出现) 我使用的是来自adapted to location service的示例 我不明白的是,尽管启用了GPS,但为什么没有搜索GPS信号(但我正在获取坐标,我想我是从wifi或手机id获取坐标的) 在我的应用程序类中,我创建了一个服务(这是一个ServicesManager,它又创建了另一个服务(用于检索位置)。我将ServicesManager
fusedLocationService = new FusedLocationService(this);
然后我呼吁:
fusedLocationService.startListeningLocationUpdates(this);
这是FusedLocationService类中的StartListeningLocationUpdate的实现
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,其中OnHandleContent提取了位置并用以下内容显示:
Location location = intent.getParcelableExtra(LocationClient.KEY_LOCATION_CHANGED);
我不知道为什么GPS不工作。你知道吗?看看这里:
您没有为您的位置请求设置优先级。请尝试使用高精度的优先级
Location location = intent.getParcelableExtra(LocationClient.KEY_LOCATION_CHANGED);