Created
September 20, 2018 04:00
-
-
Save bamnet/7fd0f87d0ff569cca650457c3c25a556 to your computer and use it in GitHub Desktop.
// source http://jsbin.com/nojujew
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<style id="jsbin-css"> | |
/* Always set the map height explicitly to define the size of the div | |
* element that contains the map. */ | |
#map { | |
height: 100%; | |
} | |
/* Optional: Makes the sample page fill the window. */ | |
html, body { | |
height: 100%; | |
margin: 0; | |
padding: 0; | |
} | |
</style> | |
<div id="map"></div> | |
<!-- Replace the value of the key parameter with your own API key. --> | |
<script src="https://maps.googleapis.com/maps/api/js?callback=initMap" async defer></script> | |
<script id="jsbin-javascript"> | |
var map; | |
function initMap() { | |
map = new google.maps.Map(document.getElementById('map'), { | |
center: {lat: 40.63801310485752, lng: -74.17071700376579}, | |
zoom: 10 | |
}); | |
loadData(); | |
} | |
async function loadData() { | |
let response = await fetch('http://njtdev.endpoints.njtapi-dev.cloud.goog:8080/v1/stations/SE/departures?stop=New%20York'); | |
let data = await response.json(); | |
for(const row of data.departures) { | |
if(row.location) { | |
const latlng = row.location.latLng; | |
const ll = {lat: parseFloat(latlng.latitude), lng: parseFloat(latlng.longitude)}; | |
console.log(ll); | |
const marker = new google.maps.Marker({position: ll, map: map}); | |
} | |
} | |
} | |
</script> | |
<script id="jsbin-source-css" type="text/css">/* Always set the map height explicitly to define the size of the div | |
* element that contains the map. */ | |
#map { | |
height: 100%; | |
} | |
/* Optional: Makes the sample page fill the window. */ | |
html, body { | |
height: 100%; | |
margin: 0; | |
padding: 0; | |
}</script> | |
<script id="jsbin-source-javascript" type="text/javascript">var map; | |
function initMap() { | |
map = new google.maps.Map(document.getElementById('map'), { | |
center: {lat: 40.63801310485752, lng: -74.17071700376579}, | |
zoom: 10 | |
}); | |
loadData(); | |
} | |
async function loadData() { | |
let response = await fetch('http://njtdev.endpoints.njtapi-dev.cloud.goog:8080/v1/stations/SE/departures?stop=New%20York'); | |
let data = await response.json(); | |
for(const row of data.departures) { | |
if(row.location) { | |
const latlng = row.location.latLng; | |
const ll = {lat: parseFloat(latlng.latitude), lng: parseFloat(latlng.longitude)}; | |
console.log(ll); | |
const marker = new google.maps.Marker({position: ll, map: map}); | |
} | |
} | |
}</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Always set the map height explicitly to define the size of the div | |
* element that contains the map. */ | |
#map { | |
height: 100%; | |
} | |
/* Optional: Makes the sample page fill the window. */ | |
html, body { | |
height: 100%; | |
margin: 0; | |
padding: 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var map; | |
function initMap() { | |
map = new google.maps.Map(document.getElementById('map'), { | |
center: {lat: 40.63801310485752, lng: -74.17071700376579}, | |
zoom: 10 | |
}); | |
loadData(); | |
} | |
async function loadData() { | |
let response = await fetch('http://njtdev.endpoints.njtapi-dev.cloud.goog:8080/v1/stations/SE/departures?stop=New%20York'); | |
let data = await response.json(); | |
for(const row of data.departures) { | |
if(row.location) { | |
const latlng = row.location.latLng; | |
const ll = {lat: parseFloat(latlng.latitude), lng: parseFloat(latlng.longitude)}; | |
console.log(ll); | |
const marker = new google.maps.Marker({position: ll, map: map}); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment