【问题标题】:LocatioManager issue位置管理器问题
【发布时间】:2013-09-08 16:11:47
【问题描述】:

我开发了一个 Android 应用程序,可以在谷歌地图中显示设备的当前位置。到目前为止,没有什么新鲜事,一切都在我的 ZTE Smart a7 (Android 2.3.2) 上运行良好。但是在我的新设备 LG Maximo G (Android 4.1.2) 上,这些位置没有到达。换句话说,LocationManager 始终为空。任何人都知道为什么在这个特定的设备/安卓操作系统版本上会发生这种情况?

要启动侦听器,我使用以下代码

    public void startListeners() {

    //Test if locatioManager is null
    if( this.lm.isProviderEnabled(LocationManager.GPS_PROVIDER)){
        this.lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 500L, 1F,this.currentListener);    
    }

    if( this.lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER)){
        this.lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 500L, 1F,this.currentListener);    
    }

    if(this.lm.getLastKnownLocation(LocationManager.GPS_PROVIDER) != null) {
        this.lastLocation = this.lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
    }

    if(this.lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER) != null) {

        if( this.lastLocation != null){

            if(  this.lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER).getAccuracy() > this.lastLocation.getAccuracy() ){
                this.lastLocation= this.lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
            }

        } else{
            this.lastLocation = this.lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
        }

    } 
}

谢谢大家。

【问题讨论】:

标签: android locationmanager


【解决方案1】:

如果是新设备,您是否尝试过设置>位置>从 Wifi 和网络启用位置?如果这是问题所在,您应该始终检查用户是否启用了它,如果没有,您应该将他们带到设置菜单以便他们启用它。

另外,就像 Bobbake4 所说,尝试使用新的 LocationClient API。

【讨论】:

  • 该选项已启用,如果未启用该选项,则应用程序不会启动。但返回为空。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-22
  • 2018-08-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多