Weather web app problem

I don't know what the problem in my script. Cant get through .getJson. Can you please advise:

$(document).ready(function() {

  var pLat=0;
  var pLong=0;

  function myWeather(){
  navigator.geolocation.getCurrentPosition(function(position) {  
  console.log('Geolocation permissions granted');  
  pLat = position.coords.latitude;  
  pLong = position.coords.longitude; 
  $.getJSON("" + pLat + "&lon=" + pLong +"&appid=50e74a4574951799ffff558b02debfe9", function(data) {
 $(".cityname").html("<h2>" + + "</h2>");
 $(".weather").html("<spam>" +[0].description + "</spam>"); 
  $("#getWeather").on("click", function() {

 `indent preformatted text by 4 spaces``indent preformatted text by 4 spaces`

Do you have a CodePen project you could link to instead?

It is working on iexplorer but not on chrome. It blocking the location permission in chrome browser without asking permission whereas location is full granted in chrome privacy setting.

its working see my comment below.

Chrome blocks geolocation when you’re connected to a site via HTTP. You’ll need to make sure you’re connected to CodePen via HTTPS for geolocation to work. When you do that, you’ll notice that your AJAX call doesn’t go through. That needs to be HTTPS as well, so you’ll either have to find a new API or use the proxy.

$.getJSON("" + pLat + "&lon=" + pLong +"&appid=50e74a4574951799ffff558b02debfe9", function(data) { /* ... */ )

It still not working if project opens in chrome browser. I change the code a bit.See the project link <-- connect via HTTPS

Thanks!! for pointing at “https” @PortableStick It works like a charm.

1 Like