Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weather API access solution #5

Open
akg314 opened this issue Dec 6, 2017 · 0 comments
Open

Weather API access solution #5

akg314 opened this issue Dec 6, 2017 · 0 comments

Comments

@akg314
Copy link

akg314 commented Dec 6, 2017

If you're having trouble setting up a proxy server because the firebase API doesn't work, here's another solution (you need chrome to make this work).

  1. Register on https://darksky.net/dev and get an API key
  2. Download the https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi?hl=en extension to allow CORS requests (only turn it on for your project server - turn it off for other sites or it might cause problems loading content!)
  3. Edit the app.getForecast function in your app.js file as follows, inserting your API key from step 2:
app.getForecast = function(key, label) {
    var cityToLatLon = {
      'austin': '30.3079823,-97.8938293',
      'boston': '42.313479,-71.1273685',
      'chicago': '41.8339032,-87.8725822',
      'bangalore': '12.9539598,77.4905096',
      'buenosaires': '-34.6158036,-58.5035321',
      'capetown': '-33.9137107,18.0942365',
      'london': '51.5285578,-0.2420244',
      'mcmurdo': '-77.8401137,166.6441437',
      'newyork': '40.7128,-74.0059',
      'portland': '45.5425909,-122.7948484',
      'sanfrancisco': '37.7578149,-122.5078116',
      'seattle': '47.6149938,-122.4763319',
      'sydney': '-33.7966053,150.6415579',
      'tokyo': '35.6732615,139.5699601'
    };
    var cityCoords = cityToLatLon[key];
    var url = 'https://api.forecast.io/forecast/INSERT_YOUR_API_KEY_HERE/' + cityCoords;
    // Make the XHR to get the data, then update the card
    var request = new XMLHttpRequest();
    request.onreadystatechange = function() {
      if (request.readyState === XMLHttpRequest.DONE) {
        if (request.status === 200) {
          var response = JSON.parse(request.response);
          response.key = key;
          response.label = label;
          app.updateForecastCard(response);
        }
      }
    };
    request.open('GET', url);
    request.send();
  };


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant