일부 명확하지 않은 이유 때문에 어떤 위치도 얻지 못하고 onLocationChanged()가 호출되지 않았습니다.Android GPS : "NO 위치를 찾았습니다."
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
/>
<uses-permission
android:name="android.permission.ACCESS_COARSE_LOCATION"
/>
<uses-permission
android:name="android.permission.ACCESS_FINE_LOCATION"
/>
<uses-permission
android:name="android.permission.READ_PHONE_STATE"
/>
<uses-permission
android:name="android.permission.ACCESS_NETWORK_STATE"
/>
<uses-permission
android:name="android.permission.INTERNET"
/>
출력은 다음과 같습니다 :
package com.example.gpsexample;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.Handler;
import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.view.Menu;
public class GPS_Location extends Activity implements LocationListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.d("~~~","~~~ GPS_Location onCreate");
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this);
Location l1 = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
Location l2 = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
Log.d("~~~","~~~ GPS_Location getLastKnownLocation ==> "+l1+" "+l2);
r.run();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public void onLocationChanged(Location location) {
Log.d("~~~","~~~ onLocationChanged "+location);
int latitude = (int) (location.getLatitude());
int longitude = (int) (location.getLongitude());
Log.i("~~~", "### Latitude: " + latitude + ", Longitude: " + longitude+"\n\n\n###");
}
@Override
public void onProviderDisabled(String provider) {
Log.d("~~~","~~~ onProviderDisabled"+provider);
}
@Override
public void onProviderEnabled(String provider) {
Log.d("~~~","~~~ onProviderEnabled "+provider);
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
Log.d("~~~","~~~ "+provider+" "+status+" "+extras);
}
final Handler handler = new Handler();
Runnable r = new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Log.d("~~~","~~~ GPS_Location run");
Location l = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
Log.d("~~~","GPS enabled: "+locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER));
Log.d("~~~","~~~ GPS_Location getLastKnownLocation ==> "+l);
l = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
Log.d("~~~","Network enabled: "+locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER));
Log.d("~~~","~~~ Network_Location getLastKnownLocation ==> "+l);
handler.postDelayed(this, 5000);
}
};
}
권한은 내가 위치 설정을 변경하면
D/~~~ (29852): ~~~ GPS_Location run
D/~~~ (29852): GPS enabled: true
D/~~~ (29852): ~~~ GPS_Location getLastKnownLocation ==> null
D/~~~ (29852): Network enabled: true
D/~~~ (29852): ~~~ Network_Location getLastKnownLocation ==> null
, 나는 onProviderEnabled() 호출을 볼 수 없습니다.
null 대신 위치를 가져 오는 방법은 무엇입니까?
이다에서 업데이트하시기 바랍니다
? 연결되어 있는지 확인 하시겠습니까? – Blackbelt
기기를 한 번 다시 시작하려고 시도 했습니까? – GrIsHu
위치 서비스 사용 : 설정 -> 위치 및 보안 -> 내 위치 -> 무선을 선택하고 gps를 사용합니다. – amalBit