Home > Software design >  Any address to Coordinates (lat, lang)?
Any address to Coordinates (lat, lang)?

Time:10-27

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 Error Message

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 enter image description here

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 enter image description here

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.

  • Related