with the latest Chrome they’ve finally turned off support for geolocation API on insecure networks.
getCurrentPosition() and watchPosition() are deprecated on insecure origins. To use this feature, you should consider switching your application to a secure origin, such as HTTPS. See https://goo.gl/rStTGz for more details.
i don’t know how to locate Chrome users without that API.
the example still works with my actual location, so there must be a way. but i don’t want to cheat and look at that code!
/*
*********************************
*** this works over HTTP only ***
*********************************
As of Chrome 50, there is no possibility to do
geolocation without HTTPS. Okay.
HTTPS is paid service at OpenWeatherMap.org. Okay.
Because of HTTP only then - it is freegeoip.net for geolocation.
I’m already using freegeoip.net. Here is my code. I’m facing “Mixed Content” problem because codepen works through https while freegeoip.net doesn’t do so.
So I need to find a free service that works through https to get geo coordinates. Are there any out there?
I use jQuery getJSON method but it doesn’t work in my app. I see you used native javascript for ajax. Could you explain please why my code doesn’t work?
I had a look and I don’t see a problem, but that doesn’t mean there isn’t one, only that I may not have the experience to see it…
It could be a jQuery/codepen problem. As you pointed out I’m using XHR - XMLHttpRequest and that is working. I looked over the code of the original poster JSDesign and she also solved the issue using XHR. Perhaps consider XHR for your project, at least while hosted on codepen. Sorry I cannot be of more help to you. Perhaps someone else has more to offer you…
@Mizu can I ask you about not commenting your code on Codepen? I had not come across that before, and I don’t want to misunderstand. Were you speaking of this case in particular, or not using comments on Codepen in general? Do you know why, or is it something you have just observed while using it? Thanks a lot!
I have seen some people trying to put https in front of codepen to “trick” google into allowing geoLocation. This works in some cases but shouldn’t be used as a solution. The code I’ve seen on codepen regarding this issue had a majority of it’s code commented out (for test purposes ?) and couldn’t work as is.
I should have been clearer about this, the problem was not with commenting stuff on codepen, it’s just that in this case, working code was commented out and the whole program couldn’t work.
It’s not a “trick” to use https on codepen to allow geolocation, it’s in fact the proper way to do it. When you use https (and you really should, for everything) then all APIs you hit must also be https. Thankfully there are plenty of weather APIs that work over https, such as forecast.io. In fact, openweathermaps looks like a lone standout in not working over https, so don’t use it.
Just to clear things up: there are basically two ways to do the weather project on Codepen now due to the Chrome change:
Use the geolocation API and remember to put https in the Codepen URL. For this your weather API also needs to support HTTPS, because any standard HTTP endpoint will give an error about coming from an insecure origin and fail. This rules out the OpenWeatherMap API because they don’t support HTTPS (at least not on the free plan).
Find some other way to get location data (user entry, IP lookup service), then you’re free to use http in your URL and therefore use OpenWeatherMap or another non-HTTPS API. Keep in mind that IP lookup tends to be less accurate, in some cases it might place people in another city/area completely (something a potential employer might notice when checking out your site), and won’t work well if using a proxy/VPN.
but both chrome and firefox console say that json.forEach is not a function? i tried using a local json file using my old random quote machine local set up and the error is no more so I guess the problem is in loading the json from http://freegeoip.net/json/