我試圖獲取位置和代碼的工作原理,但它不能正常工作。這裏是我的代碼Android get Location無法正常工作
// Get the location manager
LocationManager locationManager = (LocationManager)
getSystemService(LOCATION_SERVICE);
Criteria criteria = new Criteria();
String bestProvider = locationManager.getBestProvider(criteria, false);
Location location = locationManager.getLastKnownLocation(bestProvider);
try {
lat = (int)Math.round((location.getLatitude() * 1e6)) ;
lon = (int)Math.round((location.getLongitude() * 1e6)) ;
}
catch (NullPointerException e){
lat = -1;
lon = -1;
}
的問題,當使用foursqure或Facebook IM是他們直接拿到的位置,但我的應用程序返回-1,-1(有時),有時正確查找位置。什麼可能是問題,或者我該如何改進以獲得更好的當前位置?謝謝