Tuesday, 9 May 2017

get the res data from node-geocode

I'm still learning about javascript especially nodejs, and I want to get the data of city from res of the node-geocoder. Here's my code:

const
    nodeGeocoder = require('node-geocoder');

const
    tes = require('./tes');

let
    options = {
        provider: 'google',
        httpAdapter: 'https',
        apiKey: myapi,
        formatter: null
    };

let geocoder = nodeGeocoder(options);

geocoder.reverse({
    lat: tes.lat,
    lon: tes.lon
})
.then( res => {
    return city = res[0].administrativeLevels.level1long;
})
.catch( err => {
    console.log(err);
})

console.log(city);



via ijul

No comments:

Post a Comment