【发布时间】:2019-03-22 21:43:48
【问题描述】:
我正在开发 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 Gap error 箭头之间的直线是间隙。
我还在另一部智能手机上尝试了该应用,结果相同
我可以做些什么来改进 GPS 更新?
【问题讨论】:
标签: android xamarin gps fusedlocationproviderapi