package com.NoTrue;
import java.io.IOException;
import java.util.Iterator;
import java.util.Locale;
import android.app.Activity;
import android.content.Context;
import android.location.Address;
import android.location.Geocoder;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.widget.Toast;
import android.location.Criteria;
public class Main extends Activity implements LocationListener{
// LocationManager ¹× º¯¼ö ¼±¾ð
private LocationManager _Location = null;
String _BestProvider = null;
private double _Latitude = 0;
private double _Longitude = 0;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// get.. ¹«¾ùÀÎÁö ¸ð¸£°ÚÁö¸¸ °¡Á®¿Â´Ù´Â°Å°ÚÁÒ? LOCATION_SERVIECE Áö¿ª¼ºñ½º±º¿ä
_Location = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
// Criteria ÀÚ¼¼ÇÑ°Ç ¸ð¸£°ÚÁö¸¸ Áö¿ªÁ¤º¸ °¡Á®¿Ã¶§ »ó¼¼È÷ °¡Á®¿Ã°ÍÀÎÁö,
// º£Å͸® »ç¿ë¿¡ °ü·ÃµÈ ³»¿ëÀÎµí ½Í³×¿ä.
// requestLocationUpdates ÀÎÀÚ4°³, getBestProvider°ª, ½Ã°£, °Å¸®, this?
// ½Ã°£, °Å¸® µî¿¡ µû¶ó GPS ¾÷µ¥ÀÌÆ® °ü·ÃÀΰŠ°°³×¿ä( 1000 -> 1 ¹Ù²Ù¸é ¹ÌÄ¡´Â? )
Criteria _Criteria = new Criteria();
_Criteria.setAccuracy(Criteria.NO_REQUIREMENT);
_Criteria.setPowerRequirement(Criteria.NO_REQUIREMENT);
_BestProvider = _Location.getBestProvider(_Criteria, true);
_Location.requestLocationUpdates(_BestProvider, 1000, 0, this);
}
public void onLocationChanged(Location location) {
// onLocationChanged µüºÁµµ ¾Æ½Çµí.. Áö¿ªÀÌ ¹Ù²ð¶§¸¶´Ù Location °ª ¹Þ±â
_Latitude = location.getLatitude();
_Longitude = location.getLongitude();
}
@Override
public void onProviderDisabled(String provider) { }
@Override
public void onProviderEnabled(String provider) { }
@Override
public void onStatusChanged(String provider, int status, Bundle extras) { }
protected void onResume(){
super.onResume();
// ÀûÈù À̸§¸¸ ºÁµµ ´ëÃæ ¾î¸²ÁüÀÛÀÌ ´Ù µÉ²¨ °°¾Æ¿ä ¤·¤·
// ¹ºÁö ¸ð¸£Áö¸¸ locaitonÀÇ getLastKnownLocation. °¡Áö¿Ã²¨´Ù ¸¶Áö¸·ÀÇ ¾Ë°íÀÖ´Â Áö¿ªÁ¤º¸
// ^^; ÇÏÇÏÇÏ... Àü ´Ü¼øÇØ¿ä.
Location loc = _Location.getLastKnownLocation(_BestProvider);
if (loc != null){
onLocationChanged(loc);
}
_Location.requestLocationUpdates(_BestProvider, 0, 0, this);
String _Result = "";
// Áö¿ª°ªÀ» ¾Ë·Á¸é Geocoder¸¦ »ç¿ëÇØ¾ß ÇÑ´Ù°í Çϴ±º¿ä. À§, ¾Æ·¡ µÑÁß Çϳª¸¦ ¾²¸éµÅ¿ä
// Geocoder _Geocoder = new Geocoder(this);
Geocoder _Geocoder = new Geocoder(getApplicationContext(), Locale.KOREA);
Iterator<Address> _Addresses;
try {
_Addresses = _Geocoder.getFromLocation(_Latitude, _Longitude, 3).iterator();
if (_Addresses != null){
while(_Addresses.hasNext()){
Address namedLoc = _Addresses.next();
String featureName = namedLoc.getFeatureName();
_Result = String.format("%s", featureName);
// ¹Ø¿¡ ÆÁ³»¿ëÀ» ¿©±â Ãß°¡ÇÏ¸é µÅ¿ä.
}
// À§µµ, °æµµ Ãâ·ÂÇÔ
Toast.makeText(this, _Latitude + "," + _Longitude, Toast.LENGTH_LONG).show();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
ÆÁ1. //ÀÌ·¸°Ô Çغ¸¸é ºÎ»ê½Ã ¾îµð±¸ ¾îµðµ¿ ¸î¹øÁö ¿ìÆí¹øÈ£ ´Ù ³ª¿Ã²¨¿¡¿ä ^^.
String placeName = namedLoc.getLocality();
String featureName = namedLoc.getFeatureName();
String country = namedLoc.getCountryName();
//³ª¶ó¸¦ ¹ÞÀ½
String road = namedLoc.getThoroughfare();
//µµ·Î¸¦ ¹ÞÀ½.
_Result += String.format("\n[%s][%s][%s][%s]", placeName, featureName, road, country);
ÆÁ2. // À§µµ °æµµ °íµµ °ªÀ» ¾Ë¼ö°¡ ÀÖ¾î¿ä ^^
_Latitude = location.getLatitude();
_Longitude = location.getLongitude();
_Altitude = location.getAltitude();
ÆÁ3. // ¿¡¹Ä·¹ÀÌÅÍ¿¡¼ Å×½ºÆ®½Ã È¸é ¿À¸¥ÂÊ »ó´ç DDMS Ŭ¸¯Çغ¸½Ã¸é ½Ã¹Ä·¹ÀÌÅÍ¿¡¼
ÀüȰɱâ, ¹®ÀÚº¸³»±â, GPS °ª Áֱ⠵î ÀÛ¾÷À» ÇÒ ¼ö ÀÖ½À´Ï´Ù ^^