Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

458
Visualizações
Vanilla JS,Accuweather API, ref error: data not defined. Not sure what my next step should be. Must use location API to call another API
//First, get longitude and latitude from our location
window.addEventListener('load', () => {
  /*So after page loads, we can grab location*/
  let long;
  let lat;

  if (navigator.geolocation) {
    /*to find the exact position of the user*/
    navigator.geolocation.getCurrentPosition((position) => {
      longitude = position.coords.longitude; /*define long variable to use it*/
      latitude = position.coords.latitude; /*define lat variable to use it*/

      /*define api variable to use it and set equal to api key url*/
      const api = `http://dataservice.accuweather.com/locations/v1/cities/geoposition/search?apikey=tKaw1CfZNYzIxjfRsxVph6F=${lat},${long}`;
      /*fetch the api*/
      fetch(api)
        .then((response) => {
          return response.json(); /* turn data into json*/
        })
        .then((data) => {
          /*Access the actual data in now returned json*/
        });
    });
  }
});
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

I guess you have a problem with the request URL, missing &q=

your request URL

const api = `http://dataservice.accuweather.com/locations/v1/cities/geoposition/search?apikey=tKaw1CfZNYzIxjfRsxVph6F=${lat},${long}`;

proper URL

const api = `http://dataservice.accuweather.com/locations/v1/cities/geoposition/search?apikey=tKaw1CfZNYzIxjfRsxVph6F&q=${lat},${long}`;

And an important note: Make sure that you don't share your private API Key in public

about 4 years ago · Juan Pablo Isaza Relatório

0

You could try with this code, I've made some changes in fetch function according to the documentation.

Also, could you please test your apiKey in the Accuweather API website

window.addEventListener('load', () => {
    /*So after page loads, we can grab location*/
    let lat, long;
  
    if (navigator.geolocation) {
      /*to find the exact position of the user*/
      navigator.geolocation.getCurrentPosition((position) => {
        lat = position.coords.latitude; /*define lat variable to use it*/
        long = position.coords.longitude; /*define long variable to use it*/
        apiKey = ''; //your apiKey
        /*define api variable to use it and set equal to api key url*/
        const api = `http://dataservice.accuweather.com/locations/v1/cities/geoposition/search?apikey=${apiKey}&q=${lat},${long}`;
        /*fetch the api*/
        fetch(api)
          .then(response => response.json()) /* turn data into json*/
          .then((data) => {
            /*Access the actual data in now returned json*/
            console.log(data)
          });
      });
    }
  });
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda