-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
71 lines (63 loc) · 2.68 KB
/
Copy pathscript.js
File metadata and controls
71 lines (63 loc) · 2.68 KB
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
63
64
65
66
67
68
69
70
71
// getting places from APIs
function loadPlaces(position) {
const params = {
radius: 300, // search places not farther than this value (in meters)
clientId: 'FNGEK3NYNNVGR3QD150OJDNJKRUOSGNIPSMOPIMKCYWUCF0A',
clientSecret: '1NJ4YVSVKMV5LB022RBU3K4EL2W5XKTB5WW3C1GDGHUFJYAC',
version: '20300101', // foursquare versioning, required but unuseful for this demo
};
// CORS Proxy to avoid CORS problems
const corsProxy = 'https://cors-anywhere.herokuapp.com/';
// Foursquare API (limit param: number of maximum places to fetch)
// https://developer.foursquare.com/docs/api-reference/venues/search/
const endpoint = `${corsProxy}https://api.foursquare.com/v2/venues/search?intent=checkin
&ll=${position.latitude},${position.longitude}
&radius=${params.radius}
&client_id=${params.clientId}
&client_secret=${params.clientSecret}
&limit=5
&v=${params.version}`;
return fetch(endpoint)
.then((res) => {
return res.json()
.then((resp) => {
return resp.response.venues;
})
})
.catch((err) => {
console.error('Error with places API', err);
})
};
window.onload = () => {
const scene = document.querySelector('a-scene');
// first get current user location
return navigator.geolocation.getCurrentPosition(function (position) {
console.log(position);
// than use it to load from remote APIs some places nearby
loadPlaces(position.coords)
.then((places) => {
places.forEach((place) => {
const latitude = place.location.lat;
const longitude = place.location.lng;
console.log(place.name);
// add place name
const placeText = document.createElement('a-link');
placeText.setAttribute('gps-entity-place', `latitude: ${latitude}; longitude: ${longitude};`);
placeText.setAttribute('title', place.name);
placeText.setAttribute('scale', '15 15 15');
placeText.setAttribute('href', 'https://www.die-etagen.de');
placeText.addEventListener('loaded', () => {
window.dispatchEvent(new CustomEvent('gps-entity-place-loaded'))
});
scene.appendChild(placeText);
});
})
},
(err) => console.error('Error in retrieving position', err),
{
enableHighAccuracy: true,
maximumAge: 0,
timeout: 27000,
}
);
};