2014-02-06 5 views
5

사용자 장치가 미리 정의 된 위치에 가까울 때 이벤트를받는 방법에 대한 코드 샘플을 찾고 있습니다. 내가 여기에 Google 지역 정보 API를 사용하여 위치의 자동 완성 목록을 얻는 방법은 여기를 참조 :Android 위치 기반 알림/이벤트?

https://developers.google.com/places/training/autocomplete-android

을 위를 기반으로 위치를 사용하여, 내 응용 프로그램에게 통보 할 수있는 방법을 사용자가 위치에 근접 할 때 고르다. 지속적으로 위치를 폴링하는 서비스를 만드는 경우 Google 지역 정보 API의 일일 사용량이 할당 된 금액보다 많습니다 (일일 1,000 건만 요청).

+0

안녕하세요, 마이크, 해결책있어? –

답변

3

Google Play 서비스를 사용하면 전체 프로젝트는 여기에서 찾을 수 있습니다

@Override 
    public void onConnected(Bundle connectionHint) { 
     Log.d(TAG, "connected!!"); 
     Geofence cinemaFence = new Geofence.Builder() 
        .setRequestId(id) // some id for you 
        .setExpirationDuration(Geofence.NEVER_EXPIRE) 
        .setTransitionTypes(Geofence.GEOFENCE_TRANSITION_ENTER) 
        .setCircularRegion(mLatitude, mLongtitude, mRadius) 
        .build(); 

      GeofencingRequest request = new GeofencingRequest.Builder() 
        .addGeofence(cinemaFence) 
        .setInitialTrigger(GeofencingRequest.INITIAL_TRIGGER_ENTER) 
        .build(); 

      // Now we create an intent that will be fired when the user enters the region 
      Intent intent = new Intent(mContext, UserTransitionIntentService.class); 
      intent.putExtra(UserTransitionIntentService.EXTRA_FEATURES, getFeaturesFlag()); 
      PendingIntent pi = PendingIntent.getService(mContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); 
      LocationServices.GeofencingApi.addGeofences(mGoogleApiClient, request, pi); 
    } 

: 클라이언트가 당신이 이미 알고있는 좌표를 사용하여 알림을 설정할 수 있습니다 연결되어있을 때

private void setUpApi() { 
     mGoogleApiClient = new GoogleApiClient.Builder(getActivity()) 
       .addApi(LocationServices.API) 
       .addConnectionCallbacks(this) 
       .addOnConnectionFailedListener(this) 
       .build(); 
     mGoogleApiClient.connect(); 
    } 

먼저 구글 API 클라이언트를 설정 https://github.com/alexstyl/Location-Reminder

+0

대단한 답변입니다! 감사! – DeeJay