I am searching for address to geocode on the internet last two days. I haven't find any better solution. I am building a api with express graphql. For gecoding First of all I use this
Then I am searching on. At last I find one solution in medium. When I use this It also throw a error message. In that time I use
Now where I am wrong. What will be best solution for me?
Please help. Thank you very much.
CodePudding user response:
Any address to coordinate or geometry can be done with the package of
Secondly you have to install dotenv in you project. Add following code to your project root file-
require('dotenv/config');
Then add following code to .env file-
OPENCAGE_API_KEY=[Copied Api Key]
Then add following code to your project where you need-
opencage
.geocode({ q: 'Newyork, USA' })
.then((data) => {
console.log(data.results[0].geometry));
})
.catch((error) => {
console.log('error', error.message);
});
That's it. Thank you very much.