Jump to content

Akilian

Members
  • Content Count

    13
  • Joined

  • Last visited

Posts posted by Akilian


  1. Well, I got the alerts to display, but still no weather.

     

     

    function showLocation(position) {
    var xmlHttp = new XMLHttpRequest(),
    latitude = position.coords.latitude,
    longitude = position.coords.longitude,
    weatherInform,
    elWeatherIcon = document.querySelector("#weather-icon"),
    elWeatherTemp = document.querySelector("#weather-temp"),
    elWeatherMax = document.querySelector("#weather-max"),
    elWeatherMin = document.querySelector("#weather-min"),
    elWeatherSum1 = document.querySelector("#weather-sum1"),
    coords,
    weather,
    weatherMax,
    weatherMin,
    weatherSum1,
    weatherIcon,
    weatherTemp;
    weather = URL_WEATHER_DATA + coords + URL_WEATHER_DATA2;
    coords = latitude + "," + longitude;
    alert(weather);
    alert(coords);
    xmlHttp.overrideMimeType("application/json");
    xmlHttp.open("GET", weather, false);
    if (xmlHttp.responseText) {
    // Parses responseText to JSON
    weatherInform = JSON.parse(xmlHttp.responseText);
    weatherIcon = weatherInform.currently.icon;
    weatherSum1 = weatherInform.daily.data[0].summary;
    weatherTemp = weatherInform.currently.temperature;
    weatherMax = weatherInform.daily.data[0].temperatureMax;
    weatherMin = weatherInform.daily.data[0].temperatureMin;
    elWeatherMax.innerHTML = weatherMax + " / ";
    elWeatherMin.innerHTML = weatherMin;
    elWeatherTemp.innerHTML = weatherTemp;
    elWeatherSum1.innerHTML = weatherSum1;
    elWeatherIcon.style.backgroundImage = "url('./image/weather_icon/" + weatherIcon + ".png')";
    }
    xmlHttp.send();
    }

  2. I'm starting to understand but I'm having issues with the url.



    if(navigator.geolocation){

    // timeout at 60000 milliseconds (60 seconds)

    var options = {timeout:60000};

    navigator.geolocation.getCurrentPosition(updateWeather, errorHandler, options);

    }


    else{

    alert("Sorry, browser does not support geolocation!");

    }

    }




    function updateWeather(position) {


    var coords = document.getElementById();


    coords.innerHTML = position.coords.latitude + "," + position.coords.longitude;


    xmlHttp.open("GET", URL_WEATHER_DATA + coords.innerHTML + "?exclude=hourly,minutely,alerts,flags?units=auto",false);

  3. navigator.geolocation.getCurrentPosition(updateWeather, errorHandler, options);

     

    You tell it which function to call when it gets the position, so tell it to call updateWeather and then change that function so that it takes the passed coordinates and uses them.

    Is this right?

     

     

     

    var x = document.getElementById("demo");
    function showLocation(position) {
    var latitude = position.coords.latitude;
    var longitude = position.coords.longitude;
    x.innerHTML = latitude + "," + longitude;
    navigator.geolocation.getCurrentPosition(updateWeather, errorHandler);
    }
    function errorHandler(err) {
    if(err.code === 1) {
    alert("Error: Access is denied!");
    }
    else if( err.code === 2) {
    alert("Error: Position is unavailable!");
    }
    }
    function getLocation(){
    if(navigator.geolocation){
    // timeout at 60000 milliseconds (60 seconds)
    var options = {timeout:60000};
    navigator.geolocation.getCurrentPosition(showLocation, errorHandler, options);
    }
    else{
    alert("Sorry, browser does not support geolocation!");
    }
    }
    And in the weather function, what do I put in the url?
    xmlHttp.open("GET", URL_WEATHER_DATA + getLocation() + "?exclude=hourly,minutely,alerts,flags?units=auto",false);

  4. Have you read through this?

     

    http://www.w3schools.com/html/html5_geolocation.asp

     

    http://www.w3schools.com/js/js_ajax_examples.asp

     

    In your above code you have a global var x declared as an element and then later you seem to think it is a string?

    Yes, I have read those. i can get the coordinates to send via alert but cannot link it with the weather function. What should I put for location so it calls for the coordinates. And, thank you both for the assistance.


  5. My weather function works when I enter the coordinates myself. I'm trying to use a get location function to find and enter them in but it's not working. Please help.

     

    ////////////////////////////////////////////////////////////////////////////////////////////////

    var x = document.getElementById("demo");
    function showLocation(position) {
    var latitude = position.coords.latitude;
    var longitude = position.coords.longitude;
    x.innerHTML = latitude + "," + longitude;
    }
    function errorHandler(err) {
    if(err.code === 1) {
    alert("Error: Access is denied!");
    }
    else if( err.code === 2) {
    alert("Error: Position is unavailable!");
    }
    }
    function getLocation(){
    if(navigator.geolocation){
    // timeout at 60000 milliseconds (60 seconds)
    var options = {timeout:60000};
    navigator.geolocation.getCurrentPosition(showLocation, errorHandler, options);
    }
    else{
    alert("Sorry, browser does not support geolocation!");
    }
    }
    ///////////////////////////////////////////////////////////////////////////////////////////////
    function updateWeather() {
    var xmlHttp = new XMLHttpRequest(),
    location = x;
    xmlHttp.overrideMimeType("application/json");
    xmlHttp.open("GET", URL_WEATHER_DATA + location + URL_WEATHER_DATA2,false);
×
×
  • Create New...