-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdriver.js
65 lines (43 loc) · 1.41 KB
/
driver.js
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
58
59
60
61
62
const initMap = (lat,lon) =>{
var map = L.map('map').setView([lat, lon], 15);
L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 19,
attribution: '© OpenStreetMap'
}).addTo(map);
var marker = L.marker([lat, lon]).addTo(map);
var ghRouting = new GraphHopper.Routing({
key: '355f9c3e-b759-440d-80ac-3a9610ea4832',
vehicle: 'ambulance',
});
var startingLocation = [lat, lon];
var radius = 2000;
var poiType= 'hospital';
ghRouting.clearPoints();
ghRouting.addPoint(startingLocation[0], startingLocation[1]);
ghRouting.doRequest('pointofinterest')
.then(function (json) {
var pois = json.pois;
pois.forEach(function (poi) {
var poiMarker = L.marker([poi.lat, poi.lon]).addTo(map);
poiMarker.bindPopup(poi.name);
});
})
.catch(function (err) {
console.error('Error finding nearby points of interest:', err);
});
}
if("geolocation" in navigator){
navigator.geolocation.getCurrentPosition(
(position) => {
const lat = position.coords.latitude;
const lon = position.coords.longitude;
console.log(`latitude: ${lat}, longitude: ${lon}`);
initMap(lat,lon)
},
(error) =>{
console.error("Error getting user location:", error)
}
)
} else{
console.error("Geolocation is not supported by this browser.");
}