我有一個奇怪的問題,花了很多分鐘,現在試圖找出這一點。對於Android Market中的我的NFC Checkin應用程序,我正在訪問用戶的位置以進行Foursquare搜索。Android LocationListener.onLocationChanged從來沒有叫
所以,這裏的大概我做什麼(類似的代碼已經工作過 - 對AA的Galaxy Nexus,但現在我仍然在Android 4.0.2):
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_MEDIUM);
String providerName = locationManager.getBestProvider(criteria, true);
Location loc = locationManager.getLastKnownLocation(providerName);
showSearchUI();
if (loc.getTime() > (new Date().getTime() - 1000*2*60)) //2Minutes back
{
Log.d("demo", "LastKnownLocation is good enough, using this location!");
startVenueSearch(loc);
}
else
{
Log.d("demo", "Requesting network location updates...");
locationManager.requestLocationUpdates(providerName, 0, 0, this);
}
活動實現了LocationListener的接口,所以這裏是onLocationChanged方法:
@Override
public void onLocationChanged(Location location) {
locationManager.removeUpdates(this);
Log.d("demo", "Got fresh location, beginning... " + location.getLatitude() + "/" + location.getLongitude());
//fake hybris
//location.setLatitude(48.150098d);
//location.setLongitude(11.546026d);
startVenueSearch(location);
}
問題:我只是得不到位置更新。我只是繞過代碼,將代碼從直接調用NetworkProvider改爲基於標準的搜索提供程序,但它仍然不起作用。任何人?
您是否找到解決方案? – 4gus71n 2013-11-22 13:36:29