Skip to content
Extraits de code Groupes Projets
Valider 3ee0bcd2 rédigé par Derriick's avatar Derriick
Parcourir les fichiers

Get Traffic w/ MSDN API

parent 2576a045
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
"use strict";
/*
severity: 1: LowImpact
2: Minor
3: Moderate
4: Serious
type: 1: Accident
2: Congestion
3: DisabledVehicle
4: MassTransit
5: Miscellaneous
6: OtherNews
7: PlannedEvent
8: RoadHazard
9: Construction
10: Alert
11: Weather
*/
var key = "AvzexU5VKPHhX47Vf8VInRucqR0YQLXDFpEJL24-ZuhUVC0PAnEjNcOQjKf43Efg";
var latOffset = 1;
var lonOffset = 1;
var getTraffic = (lat, lon) => {
var options = ["o=json", "severity=2,3,4", "type=2"];
var coords = [lat - latOffset, lon - lonOffset, lat + latOffset, lon + lonOffset];
var url = "http://dev.virtualearth.net/REST/V1/Traffic/Incidents/" + coords.join(',') + "/true?" + options.join('&') + "&key=" + key;
console.log("latitude: " + lat);
console.log("longitude: " + lon);
fetch(url)
.then(response => {
console.log(response.json());
})
.catch(() => {
console.log("oups");
});
}
if ("geolocation" in navigator) {
navigator.geolocation.getCurrentPosition(function(position) {
getTraffic(position.coords.latitude, position.coords.longitude)
});
}
else {
console.log("Geolocation isn't available");
}
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter