개발/openApi
[openAPI]마스크 판매 정보 받아오기
개발햄
2020. 3. 20. 15:08
마스크 API
SERVERS | https://8oi9s0nnth.apigw.ntruss.com/corona19-masks/v1/ |
・중심 좌표(위/경도)를 기준으로 반경(미터단위) 안에 존재하는 판매처 및 재고 상태 등의 판매 정보 제공
방식 | GET | |
/storesByGeo/json | ||
Param1 | let (number) | 위도(wgs84 좌표계) / 최소:33.0, 최대:43.0 |
Param2 | lng (number) | 경도(wgs84 표준) / 최소:124.0, 최대:132.0 |
Param3 | m (number) | 반경(미터) / 최대 5000(5km)까지 조회 가능 |
const COORDS = "coords";
const range = 5000;
function gandleGeoError() {
console.log("Can`t access geo localtion");
}
function saveCoords(coordsObj) {
localStorage.setItem(COORDS, JSON.stringify(coordsObj));
}
function handleGeoSucces(position) {
const latitude = position.coords.latitude;
const longitude = position.coords.longitude;
const coordsObj = {
// latitude: latitude
latitude,
longitude
};
saveCoords(coordsObj);
getRangeMasksInfo(latitude, longitude, range);
}
function askForCoords() {
// success:handleGeoSucces , fail : gandleGeoError
navigator.geolocation.getCurrentPosition(handleGeoSucces, gandleGeoError);
}
function getRangeMasksInfo(latitude, longitude, range) {
// API 호출 패스
fetch(
`https://8oi9s0nnth.apigw.ntruss.com/corona19-masks/v1/storesByGeo/json?lat=${latitude}&lng=${longitude}&m=${range}`
)
.then(function(response) {
// fetch
return response.json();
})
.then(function(json) {
console.log(json);
});
}
function loadCoords() {
const loadedCoords = localStorage.getItem(COORDS);
if (loadedCoords === null) {
askForCoords();
} else {
const parseCoords = JSON.parse(loadedCoords);
getRangeMasksInfo(parseCoords.latitude, parseCoords.longitude, range);
}
}
SERVERS | https://8oi9s0nnth.apigw.ntruss.com/corona19-masks/v1/ |
・주소를 기준으로 해당 구 또는 동내에 존재하는 판매처 및 재고 상태 등의 판매 정보 제공.
예- '서울특별시 강남구' or '서울특별시 강남구 논현동'
('서울특별시' 와 같이 '시'단위만 입력하는 것은 불가능합니다.)
방식 | GET | |
/storesByAddr/json | ||
Param1 | address(String) | 검색 기준이 될 주소 |
function getSearchAddressMasksInfo() {
// 주소 검색 값
const address = document.getElementById("input_address").value;
fetch(
`https://8oi9s0nnth.apigw.ntruss.com/corona19-masks/v1/storesByAddr/json?address=${address}`
)
.then(function(response) {
// fetch
return response.json();
})
.then(function(json) {
//로그출력
console.log(json.stores);
});
}