Open tomwillshare opened 8 years ago
I've just had a quick look and it looks like you've got 2 issues.
Firstly, in order to get data from the web service, you need to make a slightly different request. Open up the javascript console and you will see it complaining about Access-Control-Allow-Origin
.
To make the request you need to use JSONP, like this:
$.getJSON('http://api.open-notify.org/iss-now.json?callback=?', function(data) {
var lat = data['iss_position']['latitude'];
var lon = data['iss_position']['longitude'];
});
Next you can remove the for
loop because you only have one set of data. From the globe.addData
function signature, I'm guessing it would be:
globe.addData([lat, lon], {format: 'magnitude', name: "Now", animated: true})
It might be easier if you remove the existing code that is displaying the data by years to just the bare minimum required to display the globe, and then use the new request data to add the position on the globe.
You will also need to add something to force the page to refresh, something like this:
<meta http-equiv="refresh" content="60">
Where the 60
is the number of seconds between refreshes.
Hope that helps 😊
Attempt one uploaded, it definitely refreshes correctly now, and i've hacked away all the year references i dare, but a bit of work to do to make the globe appear still. Will continue working on it!
think i may need to add <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
to use the $.getJSON bit?
ah yeah you will need jquery, good spot!
Do i stick that in the head, or the body of the html? I seem to get a load of text covering my webpage when i put it in either...
Yeah it can just go in the head
. Not sure why you would be getting a load of text though 😕 are you missing a speech mark or something?
Almost certainly, i'll track it down! i'm getting in the bad habit of editing the code in the file manager of the cpanel. Do you ever do that, or just work in a text editor and upload it each time to see if it worked? I feel i'm probably being very inefficient somewhere!
haha yeah I never edit live on the server. You can probably get away with that when you're just editing one file, but once you start needing to make changes to multiple files, it won't work.
I use Atom as my code editor, and everything is in Git. I usually do all my work on a locally running web server so I can see the changes quickly, and then I deploy it via Git.
But I wouldn't worry too much about all of that right now.
This is something i've been playing around with. It's a webGL interactive globe thingy google made as an experiment and gave out the code for here (https://www.chromeexperiments.com/globe)
I started with the index(2).html file which calls up iss.json to show on the globe a blue bar at a set coordinate. The iss.json file is formatted like this: (longitude, latitude, size of bar) like they tell you too on the google globe website, and it works fine (see here http://www.tomwillshare.com/globe/index.html)
Now i want to change the iss.json file so it calls up the live position of the international space station, and so will show it updating every few seconds and so will show the blue bar moving around earth every 90 mins or so, just like the space station. I found a continually updating .json file here: http://api.open-notify.org/iss-now.json so was going to call that up instead, but am struggling since it's in a different format than my current .json file.
I'm playing with the index1.html file to try and make it work, but struggling. I know i need to call up the 'longitude' and 'latitude' variables instead of the original fixed values from the iss.json file. so i think the line where my code falls down is just after the parsing of the .json file where i currently have:
for (i=0;i<data.length;i++) { globe.addData(data[i][1], {format: 'magnitude', name: data[i][0], animated: true});
But at the limit of my basic knowledge now! a couple of hours of googling has left me even more confused! Any ideas??