forked from NielsMartensGitH/EVOnTheGo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
testrouting.html
57 lines (47 loc) · 2.27 KB
/
testrouting.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<!-- this html is only for testing purposes!! -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div class="container">
<label for="fromLocation">From: </label>
<input type="text" id="fromLocation">
<label for="toLocation">To: </label>
<input type="text" id="toLocation">
<button type="button" onClick="getLocationName();">Get Route</button>
<div id="locations">
</div>
</div>
<script>
//// EXAMPLE ROUTING POINT A TO B: https://api.tomtom.com/routing/1/calculateRoute/50.842289%2C5.305940%3A51.225159%2C2.913830/json?instructionsType=text&routeRepresentation=summaryOnly&avoid=unpavedRoads&travelMode=car&vehicleEngineType=electric&key=dnA4PR9uKOU3Ltk0V7Fb8A5t6vHnsguc
// =============== API PARAMETERS AND KEY =======================
const key = "dnA4PR9uKOU3Ltk0V7Fb8A5t6vHnsguc"; // API Key
const category = "electric%20vehicle%20station"; // filter for all electric vehicle stations used in api
const limit = 100; // limit is the amount of search results
// ================= GET Latidude and Longitude bases on departure/destination text input =================
function getLocationName() {
const departure = document.getElementById("fromLocation");
fetchGeoLocation(departure.value);
const destination = document.getElementById("toLocation");
fetchGeoLocation(destination.value);
};
async function fetchGeoLocation(location) {
try {
const response = await fetch("https://api.tomtom.com/search/2/geocode/" + location + ".json?key=" + key);
const data = await response.json();
const lat = data.results[0].position.lat;
const lon = data.results[0].position.lon;
document.getElementById("locations").innerHTML += `<p>lat/long for <b>${location}</b> is ${lat} latitude and ${lon} longitude<p>`
}
catch(error) {
console.log(error);
}
}
</script>
</body>
</html>