tv1 = (TextView)findViewById(R.id.tv1);
tv2 = (TextView)findViewById(R.id.tv2);
lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
Criteria c= new Criteria();
provider = lm.getBestProvider(c, true);
if(provider == null || !lm.isProviderEnabled(provider)){
List<String> list = lm.getAllProviders();
for(int i = 0; i< list.size(); i++){
String temp = list.get(i);
if(lm.isProviderEnabled(temp)){
provider = temp;
break;
}
}
}
Location location = lm.getLastKnownLocation(provider);
if(location == null){
Toast.makeText(this, "사용가능한 위치 정보 제공자가 없습니다.",Toast.LENGTH_SHORT ).show();
}else{
onLocationChanged(location);
}
@Override
public void onResume(){
super.onResume();
lm.requestLocationUpdates(provider, 500, 1, this);
}
@Override
public void onPause(){
super.onPause();
lm.removeUpdates(this);
}
@Override
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
double lat = location.getLatitude();
double lng = location.getLongitude();
tv1.setText(String.valueOf(lat) + "/" + String.valueOf(lng));
tv2.setText(getAddress(lat,lng));
}
private CharSequence getAddress(double lat, double lng) {
// TODO Auto-generated method stub
String address = null;
Geocoder geocoder =new Geocoder(this, Locale.KOREA);
List<Address> list = null;
try{
list = geocoder.getFromLocation(lat, lng, 1);
}catch(Exception e){
e.printStackTrace();
}
if(list == null){
Log.e("getAddress", "주소 데이터 얻기 실패");
return null;
}
if(list.size() > 0){
Address addr = list.get(0);
address = addr.getCountryName() + ""
+ addr.getPostalCode() + ""
+ addr.getLocality() + ""
+ addr.getThoroughfare() + ""
+ addr.getFeatureName();
}
return address;
}
지오코더로 현재주소를 얻을려고하는데
좌표도 너무 멀리나오고 주소를 얻을려고하니 주소가 나오지않습니다...
뭐가 문제인가요?.... 메니페스트에 등록도 했는데 ....