오늘 일찍이 만들었지 만 작동하지 않습니다. 위치 관리자는 null을 반환하며 리스너를 구현했습니다. 문제에 대한 아이디어. 감사.LocationManager가 대상을 반환하지 않습니다.
편집 : 나는이 줄 위치가 null의 경우
Location location = locationManager.getLastKnownLocation(provider);
는 기본적으로, 그것은 아래의 경우 문장의 다른 부분으로 이동합니다 문제라고 생각합니다. 코드를 컴파일 할 때마다 위치가 업데이트되지 않는다는 것을 의미하는 else 문으로 넘어갑니다. 내 첫번째 추측은 당신이 명령 줄을 통해 또는 일식 DDMS의 perpective를 사용하여 위치 수정 프로그램을 제공하지 않는 것입니다
public class Activity1 extends Activity implements LocationListener {
/** Called when the activity is first created. */
JoshTwoActivity main;
Activity2 two;
boolean checkTick = false;
String locationplace = "";
private LocationManager locationManager;
private String provider;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
provider = locationManager.getBestProvider(criteria, false);
System.out.println(provider);
System.out.println(locationManager.getProviders(criteria, false));
System.out.println(locationManager.getProvider("network"));
System.out.println(locationManager.getAllProviders());
Location location = locationManager.getLastKnownLocation(provider);
System.out.println(locationManager.isProviderEnabled(provider));
// Initialize the location fields
if (location != null) {
System.out.println("Provider " + provider + " has been selected.");
int lat = (int) (location.getLatitude());
int lng = (int) (location.getLongitude());
System.out.println(String.valueOf(lat));
System.out.println(String.valueOf(lng));
} else {
System.out.println("Provider not available");
System.out.println("Provider not available");
}
}
/* Request updates at startup */
@Override
protected void onResume() {
super.onResume();
locationManager.requestLocationUpdates(provider, 400, 1, this);
}
/* Remove the locationlistener updates when Activity is paused */
@Override
protected void onPause() {
super.onPause();
locationManager.removeUpdates(this);
}
@Override
public void onLocationChanged(Location location) {
int lat = (int) (location.getLatitude());
int lng = (int) (location.getLongitude());
System.out.println(String.valueOf(lat));
System.out.println(String.valueOf(lng));
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String provider) {
Toast.makeText(this, "Enabled new provider " + provider,
Toast.LENGTH_SHORT).show();
}
@Override
public void onProviderDisabled(String provider) {
Toast.makeText(this, "Disenabled provider " + provider,
Toast.LENGTH_SHORT).show();
}
}
사용하시는 제공 업체는 무엇입니까? –
provider = locationManager.getBestProvider (criteria, false); 에뮬레이터에서 –
을 테스트하고 있습니다. –