# Need help with the Weather App

**URL:** <https://forum.freecodecamp.org/t/need-help-with-the-weather-app/135729>\
**Category:** General\
**Tags:** jquery, project, weatherapp, localweather\
**Created:** [July 12, 2017, 8:12pm UTC](https://forum.freecodecamp.org/t/need-help-with-the-weather-app/135729 "2017-07-12T20:12:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon56825276](https://avatars.discourse-cdn.com/v4/letter/a/cdc98d/32.png) [@anon56825276](https://forum.freecodecamp.org/u/anon56825276)\
**Post date:** [July 12, 2017, 8:12pm UTC](https://forum.freecodecamp.org/t/need-help-with-the-weather-app/135729/1 "2017-07-12T20:12:49Z")

</div>

The HTML5 Geolocation works fine but doesen’t work when I add the longtitude and latitude from the HTML5 Geolocation API.  
Here is my code:  
Please Help! 🙂

> ```
> $(document).ready(function() {
> var lon;
> var lat;
>     
> if (navigator.geolocation) {
> navigator.geolocation.getCurrentPosition(function(position) {
> lon = position.coords.longitude
> lat = position.coords.latitude;
> console.log(lon);
> console.log(lat);
> $.getJSON(url, function(data) {
> console.log(data);
> })
> });
> }
> });
> 
> ```

---

<div class="post-metadata">

**Author:** ![PortableStick](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/portablestick/32/65591_2.png) [@PortableStick](https://forum.freecodecamp.org/u/PortableStick)\
**Post date:** [July 12, 2017, 9:30pm UTC](https://forum.freecodecamp.org/t/need-help-with-the-weather-app/135729/2 "2017-07-12T21:30:09Z")

</div>

You’ll have to move your variable declaration for `url` to be inside of the `getCurrentPosition` callback. As you have it now, `lat` and `lon` are undefined.

```auto
if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(function(position) {
            lon = position.coords.longitude
            lat = position.coords.latitude;
            var url = "https://fcc-weather-api.glitch.me/api/current?lat=" + lat + "&lon=" + lon; //move it here
            console.log(lon);
          console.log(lat);
            $.getJSON(url, function(data) {
                console.log(data);
            })
        });
    }

```

---

<div class="post-metadata">

**Author:** ![trimagnus](https://avatars.discourse-cdn.com/v4/letter/t/8e7dd6/32.png) [@trimagnus](https://forum.freecodecamp.org/u/trimagnus)\
**Post date:** [July 13, 2017, 2:50am UTC](https://forum.freecodecamp.org/t/need-help-with-the-weather-app/135729/3 "2017-07-13T02:50:11Z")

</div>

You’re going to come across another problem: CodePen switched to allowing only https content on June, 1 of this year. The provided fcc-weather-api is not supplying https content and is being blocked by CodePen. There is a recent post where someone addresses this issue and offers a solution. We have to use a proxy server, basically. Or find an alternative API. Good luck!

edit: The post in question [For those of you who are stuck on the Weather API Projects](https://forum.freecodecamp.org/t/for-those-of-you-who-are-stuck-on-the-weather-api-projects/135516/2)

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 17, 2021, 8:48pm UTC](https://forum.freecodecamp.org/t/need-help-with-the-weather-app/135729/4 "2021-01-17T20:48:19Z")

</div>


