I am in the process of building a local weather app on codepen. I am using geolocation.getCurrentPosition()
method to get the current position, storing the respective longitude and latitude values in lat
and lng
variables. Although when i use console.log() statements, it seems like the longitude and lat values are not returned at all. on top of which i am getting the following messages in my console:
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://sites.google.com/a/chromium.org/dev/Home/chromium-security/deprecating-powerful-features-on-insecure-origins for more details.
Stopping the execution because density of top bars is high: Object
Although i kindaa get the first error, I am a complete loss with the next two and a google search returned nothing of note. The following is my Javascript code:
$(document).ready(function() {
var location = document.getElementsByClassName("location");
getLocation();
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(getPosition);
}
}
function getPosition(position) {
var lat = position.coords.latitude;
var lng = position.coords.longitude;
console.log(lat);
var weatherURL = "http://api.wunderground.com/api/c1d9333a91ec52f6/conditions/q/" + lat + "," + lng + ".json",
forecastURL = "https://api.wunderground.com/api/c1d9333a91ec52f6/forecast/q/" + lat + "," + lng + ".json";
$.getJSON(weatherURL, weatherJSON);
function weatherJSON(jsonVal) {
console.log(jsonVal);
var currentLocation = jsonVal.currentObservation.display_location.full;
location.innerHTML = currentLocation;
}
}
});
I would like the reader to kindly explain the errors and present a solution so that the final log statement displays to the console the complete JSON file thats being fetched by the getJSON method.