Android网络提供商和gps提供商返回空值

Android网络提供商和gps提供商返回空值,android,gps-time,Android,Gps Time,我已经在我想要获得经度和纬度的地方完成了这段代码,但使用网络提供商和gps提供商,我得到的位置为空。即使启用了gps。。。为什么会这样 不获取坐标有几个原因,但如果是您的情况,因为您的gps已启用(记住gps获取坐标需要很多时间),并且您首先在代码中检查gps,由于您使用的是if-else,因此无法转到网络部分。因此,请将您的代码更改为这样,并首先检查网络 if (!isGPSEnabled && !isNetworkEnabled) { }

我已经在我想要获得经度和纬度的地方完成了这段代码,但使用网络提供商和gps提供商,我得到的位置为空。即使启用了gps。。。为什么会这样


不获取坐标有几个原因,但如果是您的情况,因为您的
gps
已启用(
记住gps获取坐标需要很多时间),并且您首先在代码中检查gps,由于您使用的是if-else,因此无法转到
网络部分。因此,请将您的代码更改为这样,并首先检查网络

if (!isGPSEnabled && !isNetworkEnabled)
        {  
        }
      else if(isNetworkEnabled){
            location = lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);   
            if(location == null)
            {
            }
        }
        else if(isGPSEnabled ) {
            location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
            if(location == null)
            {                   
                if(isNetworkEnabled)
                    location = lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);                 
                if(location == null)
                {
                }
            }
        } 

重复问题在新版安卓系统中有一些东西。。。您正在使用设备或模拟器。如果设备的版本是什么。我的错误出现在索尼手机上,有什么不同吗?在所有情况下,我的得分都是0-0。。
if (!isGPSEnabled && !isNetworkEnabled)
        {  
        }
      else if(isNetworkEnabled){
            location = lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);   
            if(location == null)
            {
            }
        }
        else if(isGPSEnabled ) {
            location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
            if(location == null)
            {                   
                if(isNetworkEnabled)
                    location = lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);                 
                if(location == null)
                {
                }
            }
        }