feat(axios-json): adjust index.js

This commit is contained in:
dancingCycle 2023-02-07 21:00:00 +01:00
parent da9df24e69
commit c26ee58061
1 changed files with 30 additions and 10 deletions

View File

@ -1,26 +1,46 @@
var axios = require('axios'); var axios = require('axios');
var qs = require('qs'); var qs = require('qs');
var data = qs.stringify({ var data = qs.stringify({
'data': '[bbox:51.990800124058914,10.045623779296875,52.552976197007524,11.01104736328125]\n[out:json]\n;\n(\n node["shop"="second_hand"];\n way["shop"="second_hand"];\n relation["shop"="second_hand"];\n);\nout center;' 'data': '[bbox:51.990800124058914,10.045623779296875,52.552976197007524,11.01104736328125][out:json];(node["shop"="second_hand"];way["shop"="second_hand"];relation["shop"="second_hand"];);out center;'
}); });
var config = { var config = {
method: 'post', method: 'post',
maxBodyLength: Infinity, maxBodyLength: Infinity,
url: 'https://overpass-api.de/api/interpreter', url: 'https://overpass-api.de/api/interpreter',
headers: { headers: {
'Content-Type': 'application/x-www-form-urlencoded' 'Content-Type': 'application/x-www-form-urlencoded'
}, },
data : data data : data
}; };
function myFunction(value,key) { function myFunction(value,key) {
console.log("key: "+key+",type: "+value.type); //console.log("key: "+key+",type: "+value.type);
if(value.tags.name===undefined){
console.log('ERROR: OSM element does NOT include name tag');
}else if(value.type==='node'){
console.log('node');
console.log('name: '+value.tags.name);
console.log('lat: '+value.lat);
console.log('lon: '+value.lon);
}else if(value.type==='way'){
console.log('way');
console.log('name: '+value.tags.name);
console.log('lat: '+value.center.lat);
console.log('lon: '+value.center.lon);
}else{
console.log('ERROR: OSM element NOT supported');
}
} }
axios(config) axios(config)
.then(function (response) { .then(function (response) {
//log JSON //log JSON
console.log(response.data); const dataObj=response.data;
//console.log("dataObj: "+dataObj);
const elemAry=dataObj.elements;
const elemAryLength=elemAry.length;
console.log("no: "+elemAryLength)
elemAry.forEach(myFunction);
}) })
.catch(function (error) { .catch(function (error) {
console.log(error); console.log(error);