Skip to content

Instantly share code, notes, and snippets.

@tmcw tmcw/-
Created Feb 5, 2014

Embed
What would you like to do?
---
layout: example
categories: example/v1.0.0
version: v1.0.0
title: International Space Station Position from Realtime API
description: Dynamic features and map position via a JSON endpoint
tags:
- markers
---
<div id='map'></div>
<!--
this example requires jQuery so that it can request locations with
JSONP. If you already have jQuery on your page, you don't need the script
tag below that includes it. -->
<script src='https://code.jquery.com/jquery-1.10.1.min.js'></script>
<script>
var map = L.mapbox.map('map', 'examples.map-zyt2v9k2')
.setView([0, 0], 7);
var station = L.marker([0, 0], {
icon: L.mapbox.marker.icon({
'marker-symbol': 'rocket',
'marker-color': '#001ADB'
})
}).addTo(map);
// Start updating the position of the space station
updatePosition();
function updatePosition() {
// This example relies on open-notify.org - if that site is down
// or experiencing difficulties, it may fail temporarily.
$.getJSON('http://api.open-notify.org/iss-now.json?callback=?', function(data) {
if (data) {
// grabbing this position from the data will be different
// for each unique way that an API can express positions.
var position = L.latLng(data.iss_position.latitude, data.iss_position.longitude);
station.setLatLng(position);
map.panTo(position);
}
// reload position in 10 seconds
window.setTimeout(updatePosition, 1000 * 10);
});
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.