마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

gps쪽 몇가지 질문드려요

0 추천
public class MainActivity extends Activity implements OnClickListener {
  
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  requestWindowFeature(Window.FEATURE_NO_TITLE);  // 타이틀바를 없개기 위함
  setContentView(R.layout.activity_main);
  
  loadGps();
  getLocation();  
 }
 
 public void loadGps() {
  Log.w("tag", "loadGPS");
  locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
  
  Criteria criteria = new Criteria();
  criteria.setAccuracy(Criteria.ACCURACY_FINE);  // 정확도
     criteria.setPowerRequirement(Criteria.POWER_LOW); // 전원 소비량
     criteria.setAltitudeRequired(false);    // 고도, 높이 값을 얻어 올지를 결정
     criteria.setBearingRequired(false);
     criteria.setSpeedRequired(false);     //속도
     criteria.setCostAllowed(true);      //위치 정보를 얻어 오는데 들어가는 금전적 비용
     provider = locationManager.getBestProvider(criteria, true); // 사용자의 상황에 따라 gps로 연동할지 네트워크로 추적하지 자동으로 결정
     listener = new GpsLocationListener();
     locationManager.requestLocationUpdates(provider, 10000, 10, listener); // 시간 & 거리
 }
 
 public  Location getLocation() {
  Location location = locationManager.getLastKnownLocation(provider);
   
     if(location ==  null) {    
    location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
    //Toast.makeText(this, "GPS Disabled, NETWORK Enabled", 1000).show();
    Log.w("tag", "get Location from NETWORK provider");
    place="";
   }     
     else if(location != null){
      double latitude = location.getLatitude();
      double longitude = location.getLongitude(); 
    
   location.getLatitude();
   location.getLongitude();
   String Text = "My current location is:"+ "Latitud ="+location.getLatitude()
       +"Longitud ="+location.getLongitude();
        
    List<Address> addresses= null;
    Geocoder gc = new Geocoder(MainActivity.this, Locale.getDefault());
    //place="";
    try{
      addresses = gc.getFromLocation(latitude, longitude, 5);
      StringBuffer sb = new StringBuffer();
     
                  if (addresses.size() > 0) {
                       for (Address addr : addresses) {
                         
                           for (int i=0;i < addr.getMaxAddressLineIndex();i++)
                              sb.append(addr.getAddressLine(i)).append("<< \n\n");
                       }
                                      
                      Address address = addresses.get(0);
                                             sb.append(address.getAddressLine(0)).append(" ");                                           
                  place = sb.toString();
                       Toast.makeText(MainActivity.this, place, 2000).show();
                      
                                     } 
                  else {
                   place="";
                  }
    
     }catch(Exception e){
      e.printStackTrace();
      place="";
      }   
     }
  return location;
 }

 

 

 

 

 

  

 

1. 코드 상 의문점 하나가.

   geocoder를 이용하여 지금 주소를 받고 있는데요

  소스상 궁금한 점이  sb.append(address.getAddressLine(0)).append(" ");

 

  이 부분에서  getAddressLine(0)에서 0이 의미하는 바를 모르겠구요.

  다른 숫자를 넣어도 되는 건지 궁금합니다.

 

두번째로,

주소를 얻어올때 어떨때는 도로명으로 나올때도 있고,

 

어떨때는 시,구, 동으로 표시가 되는데

기준점이 뭔지를 못찾겠네요;;

 

 

이게 랜덤으로 할수밖에 없는건지....

하나로 픽스 시켜서 값을 얻을 수 있는 지 궁금합니다.

부탁드려요.~

 

앤드류이드 (6,190 포인트) 님이 2013년 6월 27일 질문
앤드류이드님이 2013년 6월 27일 수정

1개의 답변

0 추천
 
채택된 답변

0은 주소를

1은 도시를

2는 나라를 받아오는듯 합니다.

http://stackoverflow.com/questions/9409195/how-to-get-complete-address-from-latitude-and-longitude

 

두번째 질문은 잘모르겠네요

냉동참치 (2,340 포인트) 님이 2013년 6월 27일 답변
앤드류이드님이 2013년 6월 27일 채택됨
...