https://www.youtube.com/watch?v=nmAtMqljH9M&t=650s&ab_channel=yoursTRULY


요거보면서 따라하고 있고

지오펜싱 간단하게 설명하자면 구글api 이용하는거고

특정 위치에 도착하면 도착했다 알려주는거임 ㅇㅇ...

이걸로 시각장애인들 버스정류장 어딘지 모르니까 도와주는 기능 넣으려고 하는데


(깃허브는 https://github.com/trulymittal/Geofencing

https://github.com/trulymittal/Notifications

https://github.com/trulymittal/BroadcastReceiverDemo)



영상 마지막 보면 알겠다만

원본영상은 지오펜싱 1개 + 클릭해서 위치선정인데

(다른 곳 클릭하면 기존에 존재하는 지오펜싱 없어짐)

나는 지오펜싱 여러개 + 처음부터 고정위치 박고 시작하는걸 원해서

(버스 정류장은 여러개니까)

.


// location1-1, 시작점2, location2-1 같은건 좌표임 

// ex) location1-1 = 37.4313, location1-2 = 44.23124 ...


@Override

    public void onMapReady(GoogleMap googleMap) {

        mMap = googleMap;

        double[][] markerLocation = {{location1-1, location1-2}, {location2-1, location2-2}, {location3-1, location3-2}}};


        //move the camera to the starting point

        LatLng latLng_start = new LatLng(시작점1, 시작점2);

        mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng_start, 16));


        for(int i = 0; i < markerLocation.length; i++) {

            LatLng latLng = new LatLng(markerLocation[i][0], markerLocation[i][1]);

            addMarker(latLng);

            addCircle(latLng, GEOFENCE_RADIUS);

            addGeofence(latLng, GEOFENCE_RADIUS);

        }

        enableUserLocation();

    }


    private void enableUserLocation() {

        if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {

            mMap.setMyLocationEnabled(true);

        } else {

            //Ask for permission

            if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.ACCESS_FINE_LOCATION)) {

                //We need to show user a dialog for displaying why the permission is needed and then ask for the permission...

                ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, FINE_LOCATION_ACCESS_REQUEST_CODE);

            } else {

                ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, FINE_LOCATION_ACCESS_REQUEST_CODE);

            }

        }

    }


    private void addMarker(LatLng latLng) {

        MarkerOptions markerOptions = new MarkerOptions().position(latLng);

        mMap.addMarker(markerOptions);

    }


    private void addCircle(LatLng latLng, float radius) {

        CircleOptions circleOptions = new CircleOptions();

        circleOptions.center(latLng);

        circleOptions.radius(radius);

        circleOptions.strokeColor(Color.argb(255, 255, 0, 0));

        circleOptions.fillColor(Color.argb(64, 255, 0, 0));

        circleOptions.strokeWidth(4);

        mMap.addCircle(circleOptions);

    }


    private void addGeofence(LatLng latLng, float radius) {


        Geofence geofence = geofenceHelper.getGeofence(GEOFENCE_ID, latLng, radius, Geofence.GEOFENCE_TRANSITION_ENTER | Geofence.GEOFENCE_TRANSITION_DWELL | Geofence.GEOFENCE_TRANSITION_EXIT);

        GeofencingRequest geofencingRequest = geofenceHelper.getGeofencingRequest(geofence);

        PendingIntent pendingIntent = geofenceHelper.getPendingIntent();


        geofencingClient.addGeofences(geofencingRequest, pendingIntent)

            .addOnSuccessListener(new OnSuccessListener<Void>() {

                @Override

                public void onSuccess(Void aVoid) {

                    Log.d(TAG, "onSuccess: Geofence Added...");

                }

            })

            .addOnFailureListener(new OnFailureListener() {

                @Override

                public void onFailure(@NonNull Exception e) {

                    String errorMessage = geofenceHelper.getErrorString(e);

                    Log.d(TAG, "onFailure: " + errorMessage);

                }

            });

    }



코드 이렇게 수정했는데

원이랑 마커 그려지는건 해결됐어도

해당지점 도착하면 알림 울리는게

가장 마지막 한 개밖에 작동을 안한다..

오늘 이거땜시 하루종일 짱구 굴리는데...



해결되면 오픈톡방으로다가 스벅커피라도 조공해본다...

졸작하는중인데 조원들한테 너무 캐리받는 중이라

미안해서라도 이 기능은 혼자 구현해보고싶음




+




저런 식으로 뜨는데

수만은 저 원들 중에서 ㅠ

알림기능 정상작동 되는 건 배열 맨 마지막 하나밖에 없다는거임