요거보면서 따라하고 있고
지오펜싱 간단하게 설명하자면 구글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);
}
});
}
코드 이렇게 수정했는데
원이랑 마커 그려지는건 해결됐어도
해당지점 도착하면 알림 울리는게
가장 마지막 한 개밖에 작동을 안한다..
오늘 이거땜시 하루종일 짱구 굴리는데...
해결되면 오픈톡방으로다가 스벅커피라도 조공해본다...
졸작하는중인데 조원들한테 너무 캐리받는 중이라
미안해서라도 이 기능은 혼자 구현해보고싶음
+
저런 식으로 뜨는데
수만은 저 원들 중에서 ㅠ
알림기능 정상작동 되는 건 배열 맨 마지막 하나밖에 없다는거임
스벅커피 ㅇㅈㄹㅋㅋㅋㅋㅋㅋㅋㅋ
ㅋㅋㅋ 너무 싸냐
와퍼로 업글해야할까?
가장 마지막 1개가 뭔소리임 ?
double[][] markerLocation = {{location1-1, location1-2}, {location2-1, location2-2}, {location3-1, location3-2}}}; 이런식으로 해가지고 for문써서 addMarker(latLng); addCircle(latLng, GEOFENCE_RADIUS); addGeofence(latLng, GEOFENCE_RADIUS); 추가하자너?
저렇게 돌리면 실제로 마커하고 원이 2개면 2개 3개면 3개가 생기는데 영상에서 나오는 특정위치 도달하면 알람울리는 기능이 한 개 밖에 작동을 안함...
위 예제를 기준으로 마커를 3개 추가한다치면 location3-1, location3-2 지점인 곳에서만 geofencing 알람기능이 울린다는거 ㅠㅠ
이벤트가 마지막으로 생성한 마커에만 들어간다 그소리아님 ?
넹 마자요
사진도 올릴게요 잠만 ㄱㄷㄱㄷ
내부에선 여러개하지말규 가장 가까운애만 만들어두삼