【问题标题】:Gps gap problem in fused location provider融合位置提供程序中的 Gps 间隙问题
【发布时间】: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


    【解决方案1】:

    无法保证您始终可以接收 GPS。

    没有 GPS 可能是由多种因素造成的,例如无法正确查看多颗卫星,但也可能是因为您的手机试图节省电池电量,而您的操作系统决定禁用 GPS。 GPS何时被禁用的确切规则对于iOS和Android都没有很好的记录,但没有焦点的后台服务或应用程序倾向于更快地禁用GPS是有道理的。

    如果(无论出于何种原因)没有 GPS,您的手机可以回退到其他方法,例如 GSM 蜂窝塔三角测量,或者在视野范围内知道 WiFi 位置。这对电池更友好。

    但是请注意,如果您的位置是由 GSM 塔确定的,那么您的准确度会下降很多,并且如果使用的是附近的 WiFi 路由器,则位置管理器会每秒不断返回一个位置,但每次都会使用相同的坐标时间,有些东西发生了变化(例如 GPS 恢复了,或者找到了新的 WiFi 路由器)。

    在这种情况下,您还会看到您正在经历的事情。

    当然,您也可能会遇到操作系统因为其他原因而停止您的应用程序或服务的情况。

    【讨论】:

    • 感谢您的回复。我知道,错误是当我开始通过我的应用程序和另一个应用程序(如 run keeper 等)进行跟踪时,另一个应用程序跟踪没有间隙
    • @BrunoCerquiare:最可能的原因是您的应用程序不在前台,并且您的操作系统认为这是浪费电池。有几种方法可以解决这个问题。例如,您可以创建一个“前台服务”来收集 GPS 数据。请参阅:developer.android.com/guide/components/services.html#Foreground
    猜你喜欢
    • 2013-09-01
    • 1970-01-01
    • 2013-08-02
    • 1970-01-01
    • 2014-11-29
    • 2014-09-05
    • 1970-01-01
    • 1970-01-01
    • 2016-09-20
    相关资源
    最近更新 更多