0

After printing the long and the lat, I want it to print out the country name. Is there a way of using the long and lat to figure out the country and then print that out to the console at the end?

  const puppeteer = require("puppeteer"); 
  const url = "https://www.google.com/";
  

  async function StartScraping() {
    await puppeteer
      .launch({
        headless: false,
      })
      .then(async (browser) => {
        const page = await browser.newPage();
  
        await page.setViewport({
          width: 1800,
          height: 800,
        });
  
        page.on("response", async (response) => {
  
         
          if (response.url().includes("CoordinateFile")) 
          {
            const location = await response.text() 
            let intlong = location.indexOf("Coordinates:")
            const longlat = location.substring(intlong +12, intlong + 44)
            //split long lat here 
            
            var long = longlat.substring(0, longlat.indexOf(',') - 5);
            var lat = longlat.substring(longlat.indexOf(',') +1, (longlat.indexOf(',') + 7));
            console.log(`Longitude: ${long}`);
            console.log(`Latitude: ${lat}`);
           

          }
  
        });
  
        await page.goto(url, {
          waitUntil: "load",
          timeout: 0,
        });
      });
  }

  StartScraping();
Nicky
  • 39
  • 5
  • Hey, have a look here https://stackoverflow.com/questions/4497728/get-country-from-latitude-longitude and here https://stackoverflow.com/questions/6159074/given-the-lat-long-coordinates-how-can-we-find-out-the-city-country – ale917k Mar 16 '22 at 21:10

0 Answers0