좌표는 실시간으로 변하는데
거리는 왜 변하지 않는지 모르겠습니다.
초보라서 다른분들 만들어 놓은걸 보고 하나씩 붙여서 해나가고 있는데
왜 거리는 안바뀌는지 잘 모르겠네요
좀 가르쳐 주세요~^^
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) {
}
}
}




onLocation 함수 내에서 다시 distance를 구하셔야 될 것같네요 onCreate함수 호출당시에 LocationA의 위치와 LocationB의 위치는 A는 getLastLocation의 위치로 B는 설정해두신상수값으로 결정되어있으므로, LocationA와 B를 멤버로 선언하시고
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;
locationA = new Location("point A"); // 수정
locationA.setLatitude(loc.getLatitude());
locationA.setLongitude(loc.getLongitude());
locationB = new Location("point B"); // 수정
locationB.setLatitude(la);
locationB.setLongitude(lo);
distance = locationA.distanceTo(locationB);
}
/*else {
Log.d("location", "location is null");
}
*/
}
public void onLocationChanged(Location location) {
// TextView를 업데이트 한다.
tvLatitude.setText(Double.toString(location.getLatitude()));
tvLongitude.setText(Double.toString(location.getLongitude()));
locationA.setLatitude(location.getLatitude());
locationA.setLongitude(location.getLongitude());
distance = locationA.distanceTo(locationB); // 추가
tvDistance.setText(Double.toString(distance));
}
이렇게 바꾸셔야 될 것 같습니다.