0

我的应用程序显示位置经纬度,并且运行良好

但是当我必须检测位置传感器状态时,例如 on , of , working , error,... 它有一些问题

我的想法是这段代码:

  Case LocationSensor1.Sensor.State of
        TSensorState.Added : label5.Text:='2';
        TSensorState.Removed : label5.Text:='3';
        TSensorState.Initializing : label5.Text:='4';
        TSensorState.Ready : label5.Text:='ready';
        TSensorState.NoData : label5.Text:='6';
        TSensorState.AccessDenied : label5.Text:='7';
        TSensorState.Error : label5.Text:='8';
        else label5.Text:='error';
  End;

但是当我打开或关闭 GPS 时,ready每次都是

如何检测和显示 GPS 传感器状态?

4

1 回答 1

0

您必须创建一个扩展该类的LocationListener类。GPS 状态变化将通过两个回调函数通知您:onProviderEnabledGPS 启用时和onProviderDisabled禁用时调用。

要注册您的听众,请使用 ((LocationManager) getApplicationContext().getSystemService(Context.LOCATION_SERVICE)).requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 0, myLocationListener); .

于 2017-09-10T05:46:54.683 回答