0
내가 다음 클래스호출 위치 관리자가
public class GPSManager {
Context MyContext;
boolean GotLocation = false;
Location CurrentLocation;
public GPSManager(Context context){
MyContext = context;
}
LocationManager locationManager = (LocationManager)MyContext.getSystemService(MyContext.LOCATION_SERVICE);
LocationListener locationlistener = new LocationListener() {
public void onLocationChanged(Location location) {
// Called when a new location is found by the network location provider.
GotLocation = true;
CurrentLocation = location;
}
// 등
에게 한
GPSManager myGPS = new GPSManager(this);
하지만 내가 실패 디버거에서와 마찬가지로 문맥 전달과 관련하여 뭔가를 믿는다. (아직도 Eclipse에 새로 추가되었다)은 null 값이다.
내가 원하는 건
은 당신이 당신의 현재 위치를 수신하여에서 onCreate 함수에서locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); locationListener = new CurrentGPSLocation();locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
를 추가 할 수 있습니다 활동에서 현재 위치 (필요는 없다 마지막 알고 위치)
이것은 올바른 잘라내 기와 붙여 넣기처럼 보이지 않습니다.이 모두가 GPSManager 생성자에 있어야합니다. – John3136
GPSManager myGPS = 새로운 GPSManager (this); – James
최소한 그 코드는 고정되어 있다고 생각하십시오. (하지만 원하는 것을하지는 못합니다.) GPSmanager mygps가 있어야합니다. 잘못된 장소에서 줄을 만들어야합니다. 감사합니다. – James