체크 박스를 통해 네트워크 제공 업체 또는 GPS 제공 업체 사용자 선택 으로 쇼 위치 애플리케이션을 만들었습니다. 사용자가 GPS 작동을 선택하지 않으면 GPS를 사용할 수 있습니다. 가까운 지역에서 집에서 충돌로 디버그 후 시간 ... 열린 지역 작업에서 반복 후 ... 아무 문제 작업 및 내부 집. 은 무엇 내가이 오류를 방지하는 방법? 어떻게됩니까? 요구는 다른 코드 응용 프로그램 자동으로 코드를 변경 최적의 공급 업체를 선택? (사용자가 아닌)이 내 코드입니다 ....사용자가 GPS 애플리케이션을 체크 할 때
// Get the location manager
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
// Define the criteria how to select the locatioin provider -> use
// default
if(gps_en==true){ //In previous activity with checkbox user choice preferences
provider = LocationManager.GPS_PROVIDER;
Location location = locationManager.getLastKnownLocation(provider);
// Initialize the location fields
if (location != null) {
System.out.println("Provider " + provider + " has been selected.");
onLocationChanged(location);
} else {
latituteField.setText("Location not available");
longitudeField.setText("Location not available");
}
}
else{
Criteria criteria = new Criteria();
provider = locationManager.getBestProvider(criteria, false);
Location location = locationManager.getLastKnownLocation(provider);
// Initialize the location fields
if (location != null) {
System.out.println("Provider " + provider + " has been selected.");
onLocationChanged(location);
} else {
latituteField.setText("Location not available");
longitudeField.setText("Location not available");
}
}
java.lang.NullPointerException
loc.LocTracker.onSensorChanged(LocTracker.java:769)
android.hardware.SensorManager$ListenerDelegate$1.handleMessage(SensorManager.java:580)
android.os.Handler.dispatchMessage(Handler.java:99)
android.os.Looper.loop(Looper.java:137)
android.app.ActivityThread.main(ActivityThread.java:4482)
java.lang.reflect.Method.invokeNative(Native Method)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794)
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:561)
dalvik.system.NativeStart.main(Native Method)
당신이 나에게 더 나은 방법을 제안 할 수 내 코드의이 시점? 권한이 있습니다. 정확성 기준이 가장 높은 앱 자동 선택 최고의 GPS 또는 네트워크 을 원합니다. 사용자가 개방 지역 앱에 GPS 제공 업체를 사용하는 경우 네트워크 제공 업체로 시작하여 GPS 제공 업체의 정확도가 더 높은지 확인하십시오. 감사합니다. .
충돌/예외를 표시하는 LogCat 스 니펫을 게시해야합니다. – Ridcully
LogCat –