当我将程序放在移动设备中时,我获取当前位置的空值,当我在模拟器中测试它时,它正在工作。我也尝试过这个网站的其他解决方案,但仍然无法正常工作。我知道问题出在lastKnownLocation中,我认为我应用它的方式是错误的。我也在户外测试它仍然没有工作。你能检查我的程序有什么问题,并解释为什么我的程序在设备中不起作用。
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
View v = inflater
.inflate(R.layout.layout_school_list, container, false);
lvList = (ListView) v.findViewById(R.id.lvSchools);
LocationManager locationManager = (LocationManager)getActivity().getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
criteria.setAltitudeRequired(true);
criteria.setBearingRequired(true);
criteria.setCostAllowed(true);
criteria.setPowerRequirement(Criteria.POWER_LOW);
String provider = locationManager.getBestProvider(criteria, true);
Log.d("","provider : "+provider);
// String provider = LocationManager.GPS_PROVIDER;
locationManager.requestLocationUpdates(provider, 1000, 0, this);
final Location currentLoc = locationManager
.getLastKnownLocation(provider);
if (currentLoc != null) {
currentLoc.getLatitude();
currentLoc.getLongitude();
onLocationChanged(currentLoc);
}
if (Distance==true){
double lat = currentLoc.getLatitude();
double lng = currentLoc.getLongitude();
ArrayList<Double> rangeList = getRangeList(lat, lng);
这是我的onLocationChange
public void onLocationChanged(Location location) {
location.getLatitude();
location.getLongitude();
}
我将它应用于大圆距离公式中,因此我想获得当前的经度和纬度。 我想在这里传递值,但它总是返回空值 double lat = currentLoc.getLatitude(); double lng = currentLoc.getLongitude();