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

안드로이드 geofence 질문드립니다

0 추천
안드로이드 geofence에 좌표 등록만 하면 알아서 모니터링 하나요??

아니면 따로 이벤트를 구현해야하나요??
우랴 (3,680 포인트) 님이 2017년 1월 12일 질문

1개의 답변

0 추천
등록된 서비스에서 이벤트가 발생합니다.

 

 

 @Override
    protected void onHandleIntent(Intent intent) {
        GeofencingEvent geoFenceEvent = GeofencingEvent.fromIntent(intent);

        if (geoFenceEvent.hasError()) {
            int errorCode = geoFenceEvent.getErrorCode();
            Log.e(TAG, "Location Services error: " + errorCode);

        } else {
            int transitionType = geoFenceEvent.getGeofenceTransition();
            String triggeredGeoFenceId = geoFenceEvent.getTriggeringGeofences().get(0)
                    .getRequestId();

            Logger.getLogger(TAG).debug("transitionType : " + transitionType);
            if (Geofence.GEOFENCE_TRANSITION_ENTER == transitionType) {
                currentLocation = ((SmartDrivingApp) getApplication()).getFirstLocation();
                mGoogleApiClient.blockingConnect(CONNECTION_TIME_OUT_MS, TimeUnit.MILLISECONDS);

                Logger.getLogger(TAG).debug("진입 ~~~~~~~~~~~~~~~~: ");
               

            } else if (Geofence.GEOFENCE_TRANSITION_EXIT == transitionType) {
                mGoogleApiClient.blockingConnect(CONNECTION_TIME_OUT_MS, TimeUnit.MILLISECONDS);
                Logger.getLogger(TAG).debug("진출 ~~~~~~~~~~~~~~~~: ");
//                showToast(this, "진출");
                mGoogleApiClient.disconnect();
                updateInOutGeofence("false", triggeredGeoFenceId);
            }

        }
    }
r기린ㄴㄴㄴ (460 포인트) 님이 2017년 1월 19일 답변
...