Geolocation


Geolocation 는 HSP 에서 기본으로 제공하는 API 로 AndroidManifest.xml 내 uses-permission 을 추가하면 사용 가능 하다. 

Example

<uses-feature android:name="android.hardware.location.gps" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

런타임 퍼미션이 필요한 API 는 아래와 같이 사용 가능 하다. 

PermissionUtils.checkPermissions(PermissionParams.builder()
    .permission(Manifest.permission.YOU_WANT_PERMISSION)
    .activity(activity)
    .listener((reqCode, result) -> {
        if (!result) {
            TODO

            return ;
        }

        TODO
    })
    .build());

Geolocation 는 Android 에서 제공하는 Geolocation 기능의  Wrapper class 이며 Geolocation 기능을 사용하기 위해 LocationData 를 인자로 받아 처리하도록 구성되어 있으며 LocationData 클래스 정보와 각각의 변수 정보는 하단에 표를 참고 한다.

LocationData Class

public static class LocationData implements Serializable {
    String error;
   final GpsData coords;
   final long timestamp;
}

GpsData Class

static class GpsData implements Serializable {
   final double latitude;
   final double longitude;
   final double altitude;
   final double accuracy;
   final double altitudeAccuracy;
}

LocationData

필드필드설명
coordslatitude위도
longitude경도
altitude높이
accuracy위경도의 정확도(meter법)
altitudeAccuracy높이의 정확도(meter법)
timestamp 정보를 수집한 시간
timestamps 정보를 수집한 시간 (해당 필드는 삭제 예정입니다.)
error 오류 발생 시 오류에 대한 설명
   

getCurrentPosition

getCurrentPosition 은 현재 단말의 위치를 정보를 얻어 그 정보를 LocationData 형태로 반환 한다. 

Example

val observer = DAPGeolocation.LocationObserver(activity)

// 3.10.18 이상
DAPGeolocation.getCurrentPosition(activity, observer, {
       // TODO
   }) {
       // TODO
   }

// 3.10.18 이하
DAPGeolocation.getCurrentPosition(observer) { result, value ->
    when (result) {
        OnResultListener.TRUE -> {
           // TODO
       }
       
       else -> {
           // TODO
       }
   }
}
LocationObserver observer = new LocationObserver(MainActivity.this);

// 3.10.18 이상
DAPGeolocation.getCurrentPosition(MainActivity.this, observer, result -> {
       // TODO
   }, e -> {
       // TODO
   });

// 3.10.18 이하
DAPGeolocation.getCurrentPosition(observer, (result, value) -> {
   if (result == OnResultListener.TRUE) {
       // TODO
   } else {
       // TODO
   }
});

watchPosition

watchPosition 은 3번째 인자인 interval 값을 참조하여 주기적으로 단말의 위치 정보를 LocationData 형태로 전달 받는데, Android 에서 제공 하는 GPS 정보 특성 때문에 이동 거리가 없는 경우 지정한 시간에 맞춰 데이터가 반환 되지 않을 수도 있다. 

Example

val observer = DAPGeolocation.LocationObserver(activity)

// 3.10.18 이상
DAPGeolocation.watchPosition(activity, observer, "1", 1000, {
       // TODO
   }) {
       // TODO
   }

// 3.10.18 이하
DAPGeolocation.watchPosition(observer, "1", 1000) { result, value ->
    when (result) {
        OnResultListener.TRUE -> {
           // TODO
       }

       else -> {
           // TODO
       }
   }
}
LocationObserver observer = new LocationObserver(MainActivity.this);

// 3.10.18 이상
DAPGeolocation.watchPosition(MainActivity.this, observer, "1", 1000, result -> {
       // TODO
   }, e -> {
       // TODO
   });

// 3.10.18 이하
DAPGeolocation.watchPosition(observer, "1", 1000, (result, value) -> {
   if (result == OnResultListener.TRUE) {
       // TODO
   } else {
       // TODO
   }
});

clearWatch

clearWatch 는 watchPosition 을 clear 하는 기능으로 watchPosition 을 요청할 때 등록하였던 두 번째 인자인 watchId 와 동일한 값을 입력해야 한다. 

Example

val observer = DAPGeolocation.LocationObserver(activity)

// 3.10.18 이상
DAPGeolocation.clearWatch(activity, observer, "1", {
       // TODO
   }) {
       // TODO
   }

// 3.10.18 이하
DAPGeolocation.clearWatch(observer, "1")
LocationObserver observer = new LocationObserver(MainActivity.this);

// 3.10.18 이상
DAPGeolocation.clearWatch(MainActivity.this, observer, "1", result -> {
       // TODO
   }, e -> {
       // TODO
   });

// 3.10.18 이하
DAPGeolocation.clearWatch(observer, "1");