The FCC weather API works just fine, but this Google Places API doesn’t work and I can’t figure out why.
$(document).ready(function() {
navigator.geolocation.getCurrentPosition(function(location) {
//declare location variables
var lon = location.coords.longitude;
var lat = location.coords.latitude;
//API Keys
var gApiKey = [privatekey];
//enter google places awareness API
var googPlaceAPI = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location="+lat+","+lon+"&radius=200&key="+gApiKey;
// console.log(googPlaceAPI);
$.getJSON(googPlaceAPI, function(jsonPlace) {
$("#test").html("jsonPlace");
});
});
});
If I console log the constructed API url and paste it into a browser, it gives me the json data like I’d expect, but I can’t get it to do anything at all in the actual code.
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://s.codepen.io' is therefore not allowed access.
According to this post here, it looks like Google API’s might not work with codepen:
Buy, I’m also kind of in over my head here and unsure how to parse the meaning of all of this.
All I really wanted to do was make one of the front-end development projects a little fancier, and a little harder. But it looks like I might be beyond my depth here.