0
我需要一些關於Android中的關於LocationManager
的信息/幫助。我使用此代碼根據他的位置獲取用戶的特定信息,但在某些情況下,我得到provider=null
(我不確定何時,因爲該例外已上傳到我們的服務器,我無法再現它)。Android位置管理器getbestlocation返回null
下面是示例代碼:
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
Criteria crta = new Criteria();
crta.setAccuracy(Criteria.ACCURACY_FINE);
crta.setAltitudeRequired(false);
crta.setBearingRequired(false);
crta.setCostAllowed(true);
crta.setPowerRequirement(Criteria.POWER_LOW);
String provider = locationManager.getBestProvider(crta, true);
Log.d("","provider : "+provider);
// String provider = LocationManager.GPS_PROVIDER;
Location location = locationManager.getLastKnownLocation(provider);
updateWithNewLocation(location);
locationManager.requestLocationUpdates(provider, 1000, 0, locationListener);
我怎麼能當我的供應商爲空,如果有一種方式來獲得當前位置,並使用它?
在此先感謝!
我不能看到,兩行已經改變了自己的立場你的代碼和mine..except之間的差異。 – 2012-04-11 12:11:35
它工作嗎? – vipin 2012-04-11 12:12:26
它也在工作之前,但想法是如何防止提供程序爲空...因爲在某些情況下(我不知道哪些是因爲我不能再現它們,它等於空)。 – 2012-04-11 12:22:21