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

googleApiClient로 현재위치 구하기 질문합니다.

0 추천
public class MainActivity extends Activity implements
  GoogleApiClient.ConnectionCallbacks,
  GoogleApiClient.OnConnectionFailedListener {
 private GoogleApiClient mGoogleClient;

 private TextView _text;

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);


  // 오류 발생
  mGoogleClient = new GoogleApiClient.Builder(this, this, this).addApi(
    LocationServices.API).build(); 




  _text = (TextView) findViewById(R.id.textView1);

  Button btn1 = (Button) findViewById(R.id.button1);
  btn1.setOnClickListener(new View.OnClickListener() {
   @Override
   public void onClick(View v) {


    // 오류 발생
    Location location = LocationServices.FusedLocationApi
      .getLastLocation(mGoogleClient); 


   }
  });

 }

 @Override
 protected void onStart() {
  super.onStart();

  mGoogleClient.connect();
 }

 @Override
 protected void onStop() {
  mGoogleClient.disconnect();

  super.onStop();
 }

 @Override
 public void onConnected(Bundle connectionHint) {

 }

 @Override
 public void onConnectionSuspended(int cause) {
 }

 @Override
 public void onConnectionFailed(ConnectionResult connectionResult) {
  if (connectionResult.hasResolution()) {
   try {
    connectionResult.startResolutionForResult(this, 0);
   } catch (IntentSender.SendIntentException e) {
   }
  } else {
  }
 }
}

안녕하세요. 현재위치 구하기 위해 구현중에 질문 남깁니다.

googlePlayService api를 이용해서 위치를 구하려고 하는데요.

google-play-services_lib을 추가해주고 했는데  LocationServices부분만 오류가 발생합니다.

LocationServices는 따로 라이브러리 추가해야되나요?

익명사용자 님이 2015년 3월 17일 질문

2개의 답변

0 추천
아니요..

google play services 에 들어있습니다. (com.google.android.gms.location.LocationServices)

 

어떤 오류가 나는지 올려주시면 추가 답변에 도움이 될것 같습니다.
밍이~ (5,780 포인트) 님이 2015년 3월 17일 답변
LocationServices 부분에 빨간줄이 생겨서요.. 커서 갖다대면 LocationServices cannot be resolved to a variable라고 뜹니다. ctrl+shift+o 눌러도 import되는게 없습니다. google-play-services_lib이 잘못된걸까요?
google-play-services_lib 에 libs 보시면 jar 파일이 있는데요..
그거 열어서 LocationServices 가 있는지 확인해 보세요

일단 import com.google.android.gms.location.LocationServices;
가 추가되어야 합니다.
google-play-services.jar와 google-play-services.jar.properties만 있네요...삭제하고 다시 install해봐도 똑같은데 따로 LocationServices jar파일만 다운 받을 수 있나요? 찾아봐도 안나와서요..
google-play-services.jar 는 일반 zip 파일이므로 압축프로그램으로 열어보시는게 가능합니다. 압축 푸시고 com\google\android\gms\location 폴더에 LocationServices.class 가 있는지 확인해 보세요.

혹시 Android Studio 를 사용하신다면 아래분께서 답변주신대로 셋팅하시면 될것 같습니다. 6.5.87이 현재 최신버전으로 알고 있습니다.
정말 정말 감사합니다^^! 도움 많이 되었습니다!!!!!
0 추천
안드로이드 스튜디오 쓰신다면 디펜던시에 아래를 추가해주세요

    compile 'com.google.android.gms:play-services-location:6.5.87'



기존 방식과 좀 달라져서 play-services-location이라고 별도로 라이브러리가 생겼습니다. 그걸 추가해주셔야 합니다.

맨 뒤의 숫자는 버전인데, 얼마전까진 최신 버전이었습니다. 요새는 확인해보지 않아서 아직도 최신인지 확실하진 않아요 ^^
cc1232 (35,280 포인트) 님이 2015년 3월 17일 답변
...