Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

450
Views
Vanilla JS, Accuweather API, error de referencia: datos no definidos. No estoy seguro de cuál debería ser mi próximo paso. Debe usar la API de ubicación para llamar a otra 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 answers
Answer question

0

Supongo que tienes un problema con la URL de solicitud, falta &q=

su URL de solicitud

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

URL adecuada

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

Y una nota importante: asegúrese de no compartir su clave API privada en público

about 4 years ago · Juan Pablo Isaza Report

0

Puede probar con este código, he realizado algunos cambios en la función de búsqueda de acuerdo con la documentación .

Además, ¿podría probar su apiKey en el sitio web de la API de Accuweather ?

 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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!