좌표는 실시간으로 변하는데
거리는 왜 변하지 않는지 모르겠습니다.
초보라서 다른분들 만들어 놓은걸 보고 하나씩 붙여서 해나가고 있는데
왜 거리는 안바뀌는지 잘 모르겠네요
좀 가르쳐 주세요~^^
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// 텍스트뷰를 찾는다
tvLatitude = (TextView)findViewById(R.id.tvLatitude);
tvLongitude = (TextView)findViewById(R.id.tvLongitude);
tvDistance = (TextView)findViewById(R.id.tvDistance);
// LocationListener의 핸들을 얻는다
lm =(LocationManager)getSystemService(Context.LOCATION_SERVICE);
//GPS 위치 서비스에 연결한다
Location loc = lm.getLastKnownLocation("gps");
if(loc!=null) {
// TextView를 채운다
tvLatitude.setText(Double.toString(loc.getLatitude()));
tvLongitude.setText(Double.toString(loc.getLongitude()));
tvDistance.setText(Double.toString(distance));
// Location Manager에게 위치정보를 업데이트해달라고 요청한다.
locListenD = new DispLocListener();
lm.requestLocationUpdates("gps", 3000L, 10.0f, locListenD);
la=35.178456;
lo=126.909299;
Location locationA = new Location("point A");
locationA.setLatitude(loc.getLatitude());
locationA.setLongitude(loc.getLongitude());
Location locationB = new Location("point B");
locationB.setLatitude(la);
locationB.setLongitude(lo);
distance = locationA.distanceTo(locationB);
}
/*else {
Log.d("location", "location is null");
}
*/
}
private class DispLocListener implements LocationListener {
public void onLocationChanged(Location location) {
// TextView를 업데이트 한다.
tvLatitude.setText(Double.toString(location.getLatitude()));
tvLongitude.setText(Double.toString(location.getLongitude()));
tvDistance.setText(Double.toString(distance));
}
public void onProviderDisabled(String provider) {
}
public void onProviderEnabled(String provider) {
}
public void onStatusChanged(String provider, int status, Bundle extras) {
}
}
}




<meta charset="utf-8">전역 변수인 distance에 값을 할당하는 부분이 onCreate()에만 있습니다.
한 번 할당된 distance 값이 갱신되는 부분이 없어요.
의도하신 대로 작성하려면 onLocationChanged 함수 내에 distance 값을 다시 할당하는 코드가 들어가야 할 듯 합니다만...