[英]Gps gap problem in fused location provider
我正在开发GPS监视应用程序,但是当应用程序在后台运行时,我在接收GPS更新时遇到问题。 在路线期间,GPS停止更新,仅在一段时间后才开始运行。
我正在使用带有以下参数的FusedLocationProviderClient api:
return new LocationRequest()
.SetInterval( 2000 )
.SetFastestInterval( 500 )
.SetSmallestDisplacement(1)
.SetPriority( LocationRequest.PriorityHighAccuracy );
我正在使用混合服务来跟踪GPS更新。 当我启动应用程序时,我一定会使用以下方法:
public PortalCorridaServiceConnection BindService() {
if( ServiceConnection == null ) {
ServiceConnection = new PortalCorridaServiceConnection( Activity );
Intent intentService = new Intent( Activity, typeof( PortalCorridaService ) );
Activity.BindService( intentService, ServiceConnection, Bind.AutoCreate );
}
return ServiceConnection;
}
当按下“开始跟踪按钮”时,我像这样启动我的服务作为前台
public void StartForegroundService() {
MakeToast( "Servico iniciado em foreground" );
Intent intent = new Intent( Activity, typeof( Engine.PortalCorridaService ) );
if( Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.O ) {
Activity.StartForegroundService( intent );
} else {
Activity.StartService( intent );
}
}
public void RegisterForegroundService() {
// Instantiate the builder and set notification elements:
NotificationCompat.Builder builder = new NotificationCompat.Builder( this, "PORTALCORRIDA" )
.SetContentTitle( "Portal da Corrida" )
.SetContentText( "Estamos monitorando sua corrida" )
.SetSmallIcon( Resource.Drawable.ic_media_play_light );
// Build the notification:
MainNotification = builder.Build();
// Get the notification manager:
NotificationManager notificationManager = GetSystemService( Context.NotificationService ) as NotificationManager;
// Publish the notification:
//const int notificationId = 0;
//notificationManager.Notify( notificationId, notification );
// Enlist this instance of the service as a foreground service
StartForeground( SERVICE_RUNNING_NOTIFICATION_ID, MainNotification );
}
然后我打电话
fusedLocationProviderClient.RequestLocationUpdatesAsync( CreateLocationRequest(), locationCallback );
GPS间隙误差箭头之间的直线就是间隙。
我也在另一部智能手机上尝试了该应用,但结果相同
我可以做些什么来改善GPS更新吗?
无法保证您将始终拥有GPS接收功能。
没有GPS可能是由多种因素引起的,例如无法正确观看几颗卫星,但这也可能是因为您的手机试图节省电池电量,并且您的操作系统决定禁用GPS。 iOS和Android都没有很好地记录GPS禁用时间的确切规则,但是没有焦点的后台服务或应用程序倾向于更早禁用GPS是有意义的。
如果(无论出于何种原因)没有GPS,则您的手机可能会退回到其他方法(例如GSM蜂窝塔三角测量),或者在可见的情况下知道WiFi位置。 这样对电池更友好。
但是请注意,如果您的位置是由GSM塔确定的,则精度会下降很多,并且如果使用的是附近的WiFi路由器,则位置管理器会每秒返回一次位置,但是每次都会返回相同的坐标,更改(例如GPS恢复正常,或找到新的WiFi路由器)。
在这种情况下,您还将看到自己正在经历的事情。
当然,由于其他原因,您可能还会遇到操作系统停止您的应用程序或服务的情况。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.