# Local Weather - toggle

**URL:** <https://forum.freecodecamp.org/t/local-weather-toggle/73431>\
**Category:** General\
**Created:** [January 6, 2017, 6:49pm UTC](https://forum.freecodecamp.org/t/local-weather-toggle/73431 "2017-01-06T18:49:16Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![AlannaL](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/alannal/32/26063_2.png) [@AlannaL](https://forum.freecodecamp.org/u/AlannaL)\
**Post date:** [January 6, 2017, 6:49pm UTC](https://forum.freecodecamp.org/t/local-weather-toggle/73431/1 "2017-01-06T18:49:16Z")

</div>

Hi! Yet another question about the local weather toggle feature!

My .click function won’t work inside my getJSON request (not sure why) but outside I can’t access the temperature values. I’m sure there’s an easy answer, but I’ve been working on this for too long. Anyone have a suggestion?

Here’s my code:

> **[Local Weather](https://codepen.io/AlannaL/pen/egmKoQ)**
>
> ...

Thank you!

---

<div class="post-metadata">

**Author:** ![icartusacrimea](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/icartusacrimea/32/23854_2.png) [@icartusacrimea](https://forum.freecodecamp.org/u/icartusacrimea)\
**Post date:** [January 6, 2017, 7:22pm UTC](https://forum.freecodecamp.org/t/local-weather-toggle/73431/2 "2017-01-06T19:22:32Z")

</div>

Only your `<h4>` is currently loading.  
Even after I disabled my “HTTPS Everywhere” plugin.  
You’re having API issues. Yours doesn’t begin with “https,” for one.  
Also, TypeError at line 20: cannot read property ‘temp’ of undefined.  
JSON/API challenges are the most difficult, in my opinion. I still need to re-do 2 of mine before going for my Front End cert.

---

<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:** [January 6, 2017, 7:23pm UTC](https://forum.freecodecamp.org/t/local-weather-toggle/73431/3 "2017-01-06T19:23:42Z")

</div>

Here’s the conundrum: browser geolocation won’t work if your site isn’t hosted securely (`http`), and if your site _is_ hosted securely (`https`), then it will reject data from OpenWeather’s API because it’s not secure. I think the best way to fix this problem is - don’t panic here - use a different weather service. I suggest [DarkSky](https://darksky.net/dev/), but there are other good ones too. Sign up, get a new API key, and I promise you won’t have to change much of your existing code.

---

<div class="post-metadata">

**Author:** ![AlannaL](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/alannal/32/26063_2.png) [@AlannaL](https://forum.freecodecamp.org/u/AlannaL)\
**Post date:** [January 6, 2017, 7:31pm UTC](https://forum.freecodecamp.org/t/local-weather-toggle/73431/4 "2017-01-06T19:31:39Z")

</div>

Thanks for the feedback. I thought I had miraculously avoided this problem that I saw everyone else posting about, as it runs fine for me! Back to the drawing board…

---

<div class="post-metadata">

**Author:** ![AlannaL](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/alannal/32/26063_2.png) [@AlannaL](https://forum.freecodecamp.org/u/AlannaL)\
**Post date:** [January 7, 2017, 11:03am UTC](https://forum.freecodecamp.org/t/local-weather-toggle/73431/5 "2017-01-07T11:03:34Z")

</div>

So if I understood correctly, the problem you are pointing out has to do with the link I shared. Using [http://codepen.io/AlannaL/pen/egmKoQ/](http://codepen.io/AlannaL/pen/egmKoQ/) instead should solve this problem, right?

If so, fingers crossed, then I still have my original question about how to access the variables that are inside the navigation request. Is there a way to make my current strategy work, or do I need to think of another way to toggle the info?

---

<div class="post-metadata">

**Author:** ![AlannaL](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/alannal/32/26063_2.png) [@AlannaL](https://forum.freecodecamp.org/u/AlannaL)\
**Post date:** [January 7, 2017, 11:07am UTC](https://forum.freecodecamp.org/t/local-weather-toggle/73431/6 "2017-01-07T11:07:20Z")

</div>

> [@icartusacrimea](#):
>
> Also, TypeError at line 20: cannot read property ‘temp’ of undefined.

Could you please clarify what the error is on line 20? My code works well, I don’t see the problem…

---

<div class="post-metadata">

**Author:** ![icartusacrimea](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/icartusacrimea/32/23854_2.png) [@icartusacrimea](https://forum.freecodecamp.org/u/icartusacrimea)\
**Post date:** [January 7, 2017, 2:08pm UTC](https://forum.freecodecamp.org/t/local-weather-toggle/73431/7 "2017-01-07T14:08:38Z")

</div>

Hehe. Posting the link for [my weather app](https://codepen.io/LaerTrech/pen/RRPxaZ) (it’s kinda ridiculous) as “http” was what I did for a long time, but it doesn’t fix the problem. Finally switched over to Dark Sky yesterday.

The TypeError is no longer an issue, but console reads “getCurrentPosition() and watchPosition() no longer work on insecure origins. To use this feature, you should consider switching your application to a secure origin, such as HTTPS…,” so it really all comes back to the necessity of using a different weather service. I actually found Dark Sky’s documentation easier to deal with than OpenWeather’s, or maybe I’m just better at this stuff than I was a few months ago.

I also found out about this cross-origin URL you can add to the beginning of your API URL (“[https://cors-anywhere.herokuapp.com/](https://cors-anywhere.herokuapp.com/)”) that prevents security issues with Chrome browsers, specifically.

---

<div class="post-metadata">

**Author:** ![AlannaL](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/alannal/32/26063_2.png) [@AlannaL](https://forum.freecodecamp.org/u/AlannaL)\
**Post date:** [January 7, 2017, 2:19pm UTC](https://forum.freecodecamp.org/t/local-weather-toggle/73431/8 "2017-01-07T14:19:52Z")

</div>

Thanks a lot! I’ll look into this…

---

<div class="post-metadata">

**Author:** ![AlannaL](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/alannal/32/26063_2.png) [@AlannaL](https://forum.freecodecamp.org/u/AlannaL)\
**Post date:** [January 7, 2017, 2:30pm UTC](https://forum.freecodecamp.org/t/local-weather-toggle/73431/9 "2017-01-07T14:30:09Z")

</div>

I only just now saw your fully loaded page. Amazing! 😍

---

<div class="post-metadata">

**Author:** ![icartusacrimea](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/icartusacrimea/32/23854_2.png) [@icartusacrimea](https://forum.freecodecamp.org/u/icartusacrimea)\
**Post date:** [January 7, 2017, 2:43pm UTC](https://forum.freecodecamp.org/t/local-weather-toggle/73431/10 "2017-01-07T14:43:56Z")

</div>

Thank you so much. 🌷

---

<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 16, 2021, 5:08pm UTC](https://forum.freecodecamp.org/t/local-weather-toggle/73431/11 "2021-01-16T17:08:28Z")

</div>


