Geolocation


Geolocation 은 HSP 에서 기본으로 제공하는 API로 별도의 설정 없이 사용 가능하며 위치 정보 기능을 활용한 기능이다.


getCurrentPosition

현재 위치정보를 읽어온다. 위치정보는 completion에 resultDict 객체 안에 넘어온다.

Example

///////////////
// 3.10.18 이상
///////////////
let deviceAPI = DAPGeolocation()
let infoParam = DAPGeolocationGetCurrentPositionParam()
deviceAPI.execute(with: infoParam, completion: { (dict) in
   guard let resultDict = dict as NSDictionary? else {
       return
    }
   
}, failure: { (resultError) in
   guard let error = resultError else {
       return
    }
   
})


///////////////
// 3.10.18 이하
///////////////
let deviceAPI = DAPGeolocation()
let params = [Any]()
deviceAPI.execute(withActionName: "getcurrentposition", params: params, completion: { (dict) in
   guard let resultDict = dict as NSDictionary? else {
       return
    }
   
}, failure: { (resultError) in
   guard let error = resultError else {
       return
    }
   
})

///////////////
// 3.10.18 이상
///////////////
DAPDeviceAPI *deviceAPI = [DAPGeolocation new];
DAPGeolocationGetCurrentPositionParam *infoParam = [DAPGeolocationGetCurrentPositionParam new];

[deviceAPI executeWithParam:infoParam completion:^(NSDictionary *resultDict) {
    ResultData *resultData = [ResultData resultDataWithType:@"textResultDlg" resultObject:[resultDict objectForKey:kDeviceResult]];
    [self showSuccessDlgWithResultData:resultData];
} failure:^(NSError *error) {
    [self showErrorDlgWithError:error];
}];


///////////////
// 3.10.18 이하
///////////////
DAPDeviceAPI *deviceAPI = [DAPGeolocation new];

NSArray *params = [NSArray array];
[deviceAPI executeWithActionName:@"getCurrentPosition" params:params completion:^(NSDictionary *resultDict) {
    NSLog(@"%s %d\nresultDict %@", __PRETTY_FUNCTION__, __LINE__, resultDict);
} failure:^(NSError *error) {
    NSLog(@"%s %d\nerror %@", __PRETTY_FUNCTION__, __LINE__, error);
}];

 

Result

{
   "coords": {
       "accuracy": 18.698999404907227,
       "altitude": 0.0,
       "altitudeAccuracy": 18.698999404907227,
       "latitude": 37.5240917,
       "longitude": 126.9229084
    },
   "timestamp": 1485932041423,
   "timestamps": 1485932041423
}

Result 내 timestamps 는 추후 삭제될 항목이다. 


watchPosition

현재 위치정보를 주기적으로 읽어온다. 

Example

///////////////
// 3.10.18 이상
///////////////
let deviceAPI = DAPGeolocation()
let infoParam = DAPGeolocationWatchPositionParam()
infoParam.watchId = "watchId"
infoParam.interval = NSNumber(integerLiteral: 1)
deviceAPI.execute(with: infoParam, completion: { (dict) in
   guard let resultDict = dict as NSDictionary? else {
       return
    }
   
}, failure: { (resultError) in
   guard let error = resultError else {
       return
    }
   
})


///////////////
// 3.10.18 이하
///////////////
let deviceAPI = DAPGeolocation()
let watchInterval = NSNumber(integerLiteral: 1)
let params = [watchInterval, "watchId"] as [Any]
deviceAPI.execute(withActionName: "watchposition", params: params, completion: { (dict) in
   guard let resultDict = dict as NSDictionary? else {
       return
    }
   
}, failure: { (resultError) in
   guard let error = resultError else {
       return
    }
   
})

///////////////
// 3.10.18 이상
///////////////
DAPDeviceAPI *deviceAPI = [DAPGeolocation new];
DAPGeolocationWatchPositionParam *infoParam = [DAPGeolocationWatchPositionParam new];
infoParam.watchId = @"watchId";
infoParam.interval = [NSNumber numberWithInteger:3000];

[deviceAPI executeWithParam:infoParam completion:^(NSDictionary *resultDict) {
    ResultData *resultData = [ResultData resultDataWithType:@"textResultDlg" resultObject:[resultDict objectForKey:kDeviceResult]];
    [self showSuccessDlgWithResultData:resultData];
} failure:^(NSError *error) {
    [self showErrorDlgWithError:error];
}];


///////////////
// 3.10.18 이하
///////////////
DAPDeviceAPI *deviceAPI = [DAPGeolocation new];

NSArray *params = [NSArray arrayWithObjects:[NSNumber numberWithInt:3000], @"watchId", nil];
[deviceAPI executeWithActionName:@"watchPosition" params:params completion:^(NSDictionary *resultDict) {
    NSLog(@"%s %d\nresultDict %@", __PRETTY_FUNCTION__, __LINE__, resultDict);
} failure:^(NSError *error) {
    NSLog(@"%s %d\nerror %@", __PRETTY_FUNCTION__, __LINE__, error);
}];

 

Parameters

파라미터설명
첫번째 인자정보 갱신 시간(ms)
두번째 인자watch Id
  

GPS 는 이동 거리에 영향이 있기 때문에 지정한 시간에 맞춰 데이터가 반환 되지 않을 수도 있다. 

 

Result

{
   "coords": {
       "accuracy": 19.264999389648438,
       "altitude": 0.0,
       "altitudeAccuracy": 19.264999389648438,
       "latitude": 37.5240403,
       "longitude": 126.9229504
    },
   "timestamp": 1485932593408,
   "timestamps": 1485932593408
}

clearWatch

동작중인 watch를 종료한다.

Example

///////////////
// 3.10.18 이상
///////////////
let deviceAPI = DAPGeolocation()
let infoParam = DAPGeolocationClearWatchParam()
infoParam.watchId = "watchId"
deviceAPI.execute(with: infoParam, completion: { (dict) in
   guard let resultDict = dict as NSDictionary? else {
       return
    }
   
}, failure: { (resultError) in
   guard let error = resultError else {
       return
    }
   
})


///////////////
// 3.10.18 이하
///////////////
let deviceAPI = DAPGeolocation()
let params = ["watchId"] as [Any]
deviceAPI.execute(withActionName: "clearwatch", params: params, completion: { (dict) in
   guard let resultDict = dict as NSDictionary? else {
       return
    }
   
}, failure: { (resultError) in
   guard let error = resultError else {
       return
    }
   
   self.showErrorDlg(error: error)
})

///////////////
// 3.10.18 이상
///////////////
DAPDeviceAPI *deviceAPI = [DAPGeolocation new];
DAPGeolocationClearWatchParam *infoParam = [DAPGeolocationClearWatchParam new];
infoParam.watchId = @"watchId";

[deviceAPI executeWithParam:infoParam completion:^(NSDictionary *resultDict) {
    ResultData *resultData = [ResultData resultDataWithType:@"textResultDlg" resultObject:[resultDict objectForKey:kDeviceResult]];
    [self showSuccessDlgWithResultData:resultData];
} failure:^(NSError *error) {
    [self showErrorDlgWithError:error];
}];

///////////////
// 3.10.18 이하
///////////////
DAPDeviceAPI *deviceAPI = [DAPGeolocation new];

NSArray *params = [NSArray arrayWithObjects:@"watchId", nil];
[deviceAPI executeWithActionName:@"clearWatch" params:params completion:^(NSDictionary *resultDict) {
    NSLog(@"%s %d\nresultDict %@", __PRETTY_FUNCTION__, __LINE__, resultDict);
} failure:^(NSError *error) {
    NSLog(@"%s %d\nerror %@", __PRETTY_FUNCTION__, __LINE__, error);
}];

 

Parameters

파라미터설명
첫번째 인자watch Id