3
LocationManager 클래스의 인스턴스를 가져 오려고합니다 (일부 GPS 관련 정보 가져 오기). 나는 그렇게 간단한 클래스를 썼다 사용했다,하지만 내 수업 나에게Android 위치 관리자 컴파일 오류
public class LocationManagerHelper {
static Location location = null;
public static Location getLocation() {
LocationManager manager = (LocationManager) Context.getSystemService(Context.LOCATION_SERVICE);
if(manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
Location location = manager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
} else {
System.out.println("Provider is disabled");
}
return location;
}
}
감사 오류를
Cannot make a static reference to the non-static method getSystemService(String) from the type Context
이 여기주고 끝낸다.
는 내가 활성 GPS 및 Wi 모두 내 휴대 전화가 필요합니까이 작업 확인 -Fi. 지금까지 일하지 않았어. – Switch
@MMRUser : 표시된 코드의 경우 GPS가 활성 상태이면 충분합니다. 그래도 문제가 해결되지 않으면 새로운 질문을하고 코드를 실행할 때 발생하는 상황과 발생하지 않는 상황을 설명하십시오. –