Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/185.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 2.3.3姜饼-找不到位置_Android_Gps_Location_Android 2.3 Gingerbread - Fatal编程技术网

Android 2.3.3姜饼-找不到位置

Android 2.3.3姜饼-找不到位置,android,gps,location,android-2.3-gingerbread,Android,Gps,Location,Android 2.3 Gingerbread,我正在使用getLastKnownLocation方法查找用户的位置,但该方法始终为null。我已经在不同的系统版本(例如2.2.1、4.0.4)上测试了我正在使用的方法,一切正常。在2.3.3上,我总是得到null,甚至一次都没有得到location,而在其他系统版本上,我总是得到location,null甚至没有出现过一次。这在我准备的每个测试条件下都会发生,在真实设备和模拟器上都会发生 location = locManager.getLastKnownLocation(LocationM

我正在使用getLastKnownLocation方法查找用户的位置,但该方法始终为null。我已经在不同的系统版本(例如2.2.1、4.0.4)上测试了我正在使用的方法,一切正常。在2.3.3上,我总是得到null,甚至一次都没有得到location,而在其他系统版本上,我总是得到location,null甚至没有出现过一次。这在我准备的每个测试条件下都会发生,在真实设备和模拟器上都会发生

location = locManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
            locManager.requestLocationUpdates(provider,0, 0, locationListener);
            location = locManager.getLastKnownLocation(provider);
            locManager.requestLocationUpdates(provider,0, 0, locationListener);
我知道getLastKnownLocation是如何工作的,我正在检查提供程序是否已启用,我正在请求位置更新,我正在清单中使用正确的权限

location = locManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
            locManager.requestLocationUpdates(provider,0, 0, locationListener);
            location = locManager.getLastKnownLocation(provider);
            locManager.requestLocationUpdates(provider,0, 0, locationListener);

我认为这个确切的系统版本有问题。有人能证实我对这个话题的看法吗?Android 2.3.3上的位置获取是否存在错误?

getLastKnownLocation
如果没有以前的位置,可以返回
null
。如果是这种情况,则需要与注册的侦听器一起等待
onLocationChanged
中的值

location = locManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
            locManager.requestLocationUpdates(provider,0, 0, locationListener);
            location = locManager.getLastKnownLocation(provider);
            locManager.requestLocationUpdates(provider,0, 0, locationListener);
请注意,GPS在大城市、建筑物内部等不起作用。。此外,一些设备还具有其他位置检索机制,如A-GPS。所以我想这也可能是一个特定于设备的问题

location = locManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
            locManager.requestLocationUpdates(provider,0, 0, locationListener);
            location = locManager.getLastKnownLocation(provider);
            locManager.requestLocationUpdates(provider,0, 0, locationListener);

当我开发地图应用程序时,2.3.3不太可能出现同样的问题。经过长时间的尝试,我找到了解决办法

location = locManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
            locManager.requestLocationUpdates(provider,0, 0, locationListener);
            location = locManager.getLastKnownLocation(provider);
            locManager.requestLocationUpdates(provider,0, 0, locationListener);
调用getLastKnownLocation和requestLocationUpdates两次,以便您的Cruent位置设置您的最后位置。
您的问题将得到解决,

关于特定于设备的问题,您可能是对的。当我在真实设备上测试应用程序时,空值问题似乎只发生在HTC Wildfire S上。
location = locManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
            locManager.requestLocationUpdates(provider,0, 0, locationListener);
            location = locManager.getLastKnownLocation(provider);
            locManager.requestLocationUpdates(provider,0, 0, locationListener);