어플을 실행시키면 상단부에 gps사용여부가 뜨지 않네요
그래서 그런지 gps값도 받아오질 못합니다..
일단 폰에서 gps사용한다고 체크 했습니다
그리고 테스트 파일(인터넷 예제)은 문제 없이 잘돌아갔습니다
주소 잘찍어내더군요 물론 그땐 gps사용중이라고 나옵니다
그래서 그 클래스를 따와서 제가 만들고있는 어플에 적용시켰는데
제꺼에 들어가자마자 gps사용여부가 꺼져버리더군요
권한도 줬습니다
internet / find,mock location
그런데 안뜨네요 ㅠㅠㅠㅠㅠ
부탁드려요 꼭 알려주세요 ~
혹시나해서 소스도 올립니다
이것이 호출하는 부분이구요
Location1 loc = new Location1();
final Location1 loc1 = loc;
juso.setText(loc.GetLocations());
Button updateJuso = (Button)findViewById(R.id.saveUpdateJusoBtn);
updateJuso.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
juso.setText(loc1.GetLocations());
}
});
클래스입니다
public class Location1 extends Activity implements LocationListener {
private LocationManager locManager;
Geocoder geoCoder;
private Location myLocation = null;
double latPoint = 0;
double lngPoint = 0;
double speedPoint = 0;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//로케이션 매니져를 가져오기 위해
locManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
// GPS로부터 위치정보 업데이트 요청
locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
// 기지국으로 부터 위치정보 업데이트 요청
locManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1000, 0, this);
// 주소를 확인하기 위한 GeoCoder Korea korean둘다가능
geoCoder = new Geocoder(this, Locale.KOREA);
}
public String GetLocations() {
StringBuffer juso = new StringBuffer();
if (myLocation != null) {
latPoint = myLocation.getLatitude(); //경도
lngPoint = myLocation.getLongitude(); //위도
speedPoint = myLocation.getSpeed(); //스피드
try {
//위도 경도를 이용하여 현재위치 주소를 가져온다
Log.i("gps","1");
List<Address> addresses;
addresses = geoCoder.getFromLocation(latPoint, lngPoint, 1);
Log.i("gps","2 "+addresses.size());
for(Address addr: addresses){
Log.i("gps","2");
int index = addr.getMaxAddressLineIndex();
for(int i=0;i<=index;i++){
Log.i("gps","3");
juso.append(addr.getAddressLine(i));
juso.append(" ");
}
juso.append("\n");
}
} catch (IOException e) {
e.printStackTrace();
}
}
return String.valueOf(juso);
// latText.setText(String.valueOf(latPoint));
// lngText.setText(String.valueOf(lngPoint));
// speedText.setText(String.valueOf(speedPoint));
// jusoText.setText(String.valueOf(juso));
}
public void onLocationChanged(Location location) {
Log.d("location", "location changed");
myLocation = location;
GetLocations();
}
하이라이터를 잘 못써서 이렇게 올린점 양해드립니다
GPS테스트를 실내에서 하신거 아닌가요?
실내에서 하신거라면 GPS신호를 받을수 없습니다.
GPS는 하늘이 보이는 위치에서만 가능합니다.
Criteria는 설정한 정보에 의해서 현재 기기에 가장 알맞는 Provider를 구할수 있습니다.
예) Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); // 정확도 criteria.setPowerRequirement(Criteria.POWER_HIGH); // 전력 소비량 criteria.setAltitudeRequired(false); // 고도, 높이 criteria.setBearingRequired(false); // 방향 criteria.setSpeedRequired(false); // 속도 criteria.setCostAllowed(false); // 금전적 비용 String provider = locationManager.getBestProvider(criteria, true); locManager.requestLocationUpdates(provider , 0, 0, this);
또 저같은 경우 provider가 GPS일 경우 어느정도 시간까지도 값을 얻지 못하면
LocationManager.NETWORK_PROVIDER로 다시 요청하는 방법을 사용합니다.



