// 최소 GPS 정보 업데이트 거리 10미터
private static final long MIN_DISTANCE_CHANGE_FOR_UPDATES = 10;
// 최소 GPS 정보 업데이트 시간 밀리세컨이므로 1분
private static final long MIN_TIME_BW_UPDATES = 1000 * 60 * 1;
protected LocationManager locationManager;
public UtilGpsInfo(Context context) {
this.mContext = context;
getLocation();
}
public Location getLocation() {
try {
locationManager = (LocationManager) mContext
.getSystemService(LOCATION_SERVICE);
// GPS 정보 가져오기
isGPSEnabled = locationManager
.isProviderEnabled(LocationManager.GPS_PROVIDER);
// 현재 네트워크 상태 값 알아오기
isNetworkEnabled = locationManager
.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
if (!isGPSEnabled && !isNetworkEnabled) {
// GPS 와 네트워크사용이 가능하지 않을때 소스 구현
} else {
this.isGetLocation = true;
if (isGPSEnabled) {
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
MIN_TIME_BW_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
if (locationManager != null) {
location = locationManager
.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (location != null) {
lat = location.getLatitude();
lon = location.getLongitude();
}
}
}
// 네트워크 정보로 부터 위치값 가져오기
if (isNetworkEnabled) {
if (location == null) {
locationManager.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER,
MIN_TIME_BW_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
if (locationManager != null) {
location = locationManager
.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
if (location != null) {
// 위도 경도 저장
lat = location.getLatitude();
lon = location.getLongitude();
}
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return location;
}
펍 질문 검색과 구글링을 통해서 구한 코드로 현재위치를 받아오는것까지는 성공을 했습니다.
예를들어서 강남에서 위치를 구한후에 신촌으로 이동해서 다시 위치정보를 받아오려고 하면
계속 강남의 위치가 잡히고 있습니다.
어느부분이 잘못 된것일까요