location.js
1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import {all, call, fork, delay, put, takeEvery, takeLatest} from 'redux-saga/effects';
import axios from 'axios';
import {coordAPIKEY} from '../env';
import {
SET_LOC_REQUEST,
SET_LOC_SUCCESS,
SET_LOC_FAILURE,
} from "../reducers/location";
function setLocationAPI(data) {
const {startTextLocation, finishTextLocation} = data;
console.log(startTextLocation, finishTextLocation);
const startRes = axios.get(`http://api.vworld.kr/req/address?service=address&request=getcoord&version=2.0&crs=epsg:4326&address=${startTextLocation}&refine=true&simple=false&format=xml&type=road&key=${coordAPIKEY}`);
const finishRes = axios.get(`http://api.vworld.kr/req/address?service=address&request=getcoord&version=2.0&crs=epsg:4326&address=${finishTextLocation}&refine=true&simple=false&format=xml&type=road&key=${coordAPIKEY}`);
return {startRes, finishRes};
}
function* setLocation(action) {
try {
console.log('saga의 setLocation', action.data);
const res = yield call(setLocationAPI, action.data);
console.log(res.startRes, res.finishRes);
const {result} = res.startRes;
console.log(result);
} catch (e) {
console.error(e);
}
};
function* watchSetLocation() {
console.log('watchSetLocation');
yield takeLatest(SET_LOC_REQUEST, setLocation);
}
export default function* locationSaga() {
yield all([
fork(watchSetLocation),
]);
};