<p><span style="color: #404040; font-family: 굴림;">/*&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">&nbsp;* GPS/Network 이용 위/경도값 구하기&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">&nbsp;*/&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">LocationManager lom;&nbsp; &nbsp; //위치정보를 얻기 위한 LocationManager 객체 선언&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">String mylat;&nbsp; &nbsp; &nbsp; //내 현재 위도&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">String mylong;&nbsp; //내 현재 경도&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">String bestProvider_name;&nbsp; &nbsp; //현재 장치에서 위치값을 줄 수 있는 센서명&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">HashMap&lt;String, String&gt; hmlocation;	</span><br style="color: #404040; font-family: 굴림;" /><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">/*&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">&nbsp;* Critical 메소드를 통해 가장 최적의 센서를 추출한다.&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">&nbsp;* 최적센서 자동추출(Gps / Network)&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">&nbsp;*/&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">public void getLocation() {&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">lom = (LocationManager)act.getSystemService(act.LOCATION_SERVICE);&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">Criteria cr = new Criteria();&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">&nbsp; &nbsp; cr.setAccuracy(Criteria.ACCURACY_FINE);&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">&nbsp; &nbsp; cr.setAltitudeRequired(true);&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">&nbsp; &nbsp; cr.setPowerRequirement(Criteria.NO_REQUIREMENT);&nbsp; &nbsp;&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">&nbsp; &nbsp; bestProvider_name = lom.getBestProvider(cr, true);&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">lom.requestLocationUpdates(bestProvider_name, 1000, 0, lol );&nbsp; //5초주기&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">}&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">/*&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">&nbsp;* LocationListener로 GPS센서값이 변할때마다 위도/경도값 가져오기&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">&nbsp;*/&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">private LocationListener lol = new LocationListener() {	&nbsp;&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">@Override&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">public void onStatusChanged(String provider, int status, Bundle extras) { }&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">@Override&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">public void onProviderEnabled(String provider) { }&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">@Override&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">public void onProviderDisabled(String provider) {&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">Toast.makeText(act, "현재 위치정보 사용이 불가능합니다.\nGPS 또는 3G를 켜주세요", Toast.LENGTH_SHORT).show();&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">}&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">@Override&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">public void onLocationChanged(Location location) {&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">// TODO Auto-generated method stub&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">mylat = Double.toString(location.getLatitude());&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">mylong = Double.toString(location.getLongitude());&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">mylat = String.format("%.7f", Double.valueOf(mylat));&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">mylong = String.format("%.7f", Double.valueOf(mylong));&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">Log.i("mylocation", bestProvider_name+"::"+mylat+":::"+mylong);&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">}&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">};&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">@Override&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">protected void onPause() {&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">// TODO Auto-generated method stub&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">super.onPause();&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">lom.removeUpdates(lol);&nbsp;</span><br style="color: #404040; font-family: 굴림;" /><span style="color: #404040; font-family: 굴림;">}</span></p>