Unable to get geocode for location
Closed this issue · 2 comments
scraly commented
I've got two troubles to identify geocoding even if it's working on openstreetmap website
Unable to get geocode for location: Tacoma, WA (USA)
Unable to get geocode for location: Burlington, VT (USA)
Unable to get geocode for location: Yogyakarta (Indonesia)
Unable to get geocode for location: Hyderabad (India)
Unable to get geocode for location: Metro Manila (Philippines)
* 20: [GitHub Field Philippines](https://githubfieldday.com/ph2024/) - Philippines
HanzCEO commented
Upon deeper inspection, not providing 'User-Agent' header violates OSM Policy:
This works:
const fetch = require('fix-esm').require('node-fetch').default;
const NodeGeocoder = require('node-geocoder');
let options = {
provider: 'openstreetmap',
fetch(url, options) {
return fetch(url, {...options, headers: { 'user-agent': 'dca-0' }})
}
};
const geocoder = NodeGeocoder(options);
const locations = ['Tacoma, WA (USA)'];
geocoder.batchGeocode(locations).then(result => {
console.dir(result, {depth:null});
});