코드의 GPS 정보를받는 데 사용되는 것은 다음과 같습니다. 앱 오류는 실제 전화입니다. 응용 프로그램의 문제가 Gps가 수신 할 때까지 기다려야한다고 생각합니다. 어떻게해야합니까?Android에서 GPS 정보를 수신 하시겠습니까?
public class Main extends Activity {
TextView text;
Location currentLocation;
double latitude;
double longitude;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
text = (TextView)findViewById(R.id.text);
LocationManager locationManager =
(LocationManager)this.getSystemService(Context.LOCATION_SERVICE);
LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
updateLocation(location);
}
public void onStatusChanged(
String provider, int status, Bundle extras) {}
public void onProviderEnabled(String provider) {}
public void onProviderDisabled(String provider) {}
};
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER, 1000, 1, locationListener);
Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
latitude=location.getLatitude();
longitude=location.getLongitude();
addressText.setText("Latitude: "+latitude+" \n"+"Longitude: "+longitude);
void updateLocation(Location location){
currentLocation = location;
latitude = currentLocation.getLatitude();
longitude = currentLocation.getLongitude();
}
}
건물에있는 경우 GPS 신호를받지 못할 수 있습니다. 너는 밖에 나가야 해. 나는 당신의 질문이 무엇 인지도 잘 모르겠습니다. – Reno
문제는 GPS 신호가 아닙니다. 위치 값은 null 값을 반환합니다. – realuser
위치 및 보안 설정에서 "GPS 위성 사용"을 선택 했습니까 ?? – Hanry