我试图获取位置并且代码有效,但它无法正常工作。这是我的代码
// 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 时,他们直接获取位置,但我的应用程序返回-1,-1(有时),有时它会准确找到位置。可能是什么问题,或者我该如何改进以更好地获得当前位置?谢谢