-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
183 lines (155 loc) · 5.26 KB
/
index.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<!DOCTYPE html>
<html lang="en" ng-app>
<head>
<meta charset="utf-8">
<title>Aire de jeux Rennes</title>
</head>
<body>
<h2>Aire de jeux Rennes</h2>
<div>
<p>My positon :</p>
<p id="position"></p>
</div>
<div id="out"></div>
<div id="out2"></div>
<div id="result" style="color:red"></div>
<script src="script.js"></script>
<!--<script>
var getJSON = function(url) {
return new Promise(function(resolve, reject) {
var xhr = new XMLHttpRequest();
xhr.open('get', url, true);
xhr.responseType = 'json';
xhr.onload = function() {
var status = xhr.status;
if (status == 200) {
resolve(xhr.response);
} else {
reject(status);
}
};
xhr.send();
});
};
getJSON('https://data.rennesmetropole.fr/api/records/1.0/search/?dataset=aires-de-jeux-des-espaces-verts-rennes&rows=10').then(function(data) {
var newUl = document.createElement('ul')
for (var key in data.records) {
newLi = document.createElement('li')
var name = data.records[key].fields.nom
var position = data.records[key].fields.geo_point_2d
newLi.innerText = name + " " + "(" + position + ")"
newUl.appendChild(newLi)
}
result.appendChild(newUl)
}, function(status) {
alert('Something went wrong.');
});
</script>-->
<!--<script>
var x = document.getElementById("position");
function getLocation() {
if (navigator.geolocation) {
x.innerText = "start"
navigator.geolocation.clearWatch(showPosition);
x.innerText = "wait"
} else {
x.innerHTML = "Geolocation is not supported by this browser.";
}
}
function showPosition(position) {
x.innerText = "in"
x.innerHTML = "Latitude: " + position.coords.latitude +
"<br>Longitude: " + position.coords.longitude;
}
getLocation();
</script>-->
<!--<script>
var x = document.getElementById("position");
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.clearWatch(listParcs);
} else {
x.innerHTML = "Geolocation is not supported by this browser.";
}
}
function listParcs(position) {
alert("sso")
x.innerHTML = "Latitude: " + position.coords.latitude +
"<br>Longitude: " + position.coords.longitude;
}
getLocation()
</script>-->
<!--<script>
function geoFindMe() {
var output = document.getElementById("out");
var output2 = document.getElementById("out2");
if (!navigator.geolocation){
output.innerHTML = "<p>Geolocation is not supported by your browser</p>";
return;
}
function success(position) {
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
output.innerHTML = '<p>Latitude is ' + latitude + '° <br>Longitude is ' + longitude + '°</p>';
var img = new Image();
img.src = "https://maps.googleapis.com/maps/api/staticmap?center=" + latitude + "," + longitude + "&zoom=13&size=300x300&sensor=false";
output.appendChild(img);
findParcs(position.coords);
}
function error() {
output.innerHTML = "Unable to retrieve your location";
}
function findParcs(current_position) {
getJSON('https://data.rennesmetropole.fr/api/records/1.0/search/?dataset=aires-de-jeux-des-espaces-verts-rennes&rows=10').then(function(data) {
var newUl = document.createElement('ul')
for (var key in data.records) {
newLi = document.createElement('li')
var name = data.records[key].fields.nom
var position = data.records[key].fields.geo_point_2d
var dif = PythagorasEquirectangular(position.latitude, position.longitude, current_position.latitude, current_position.longitude);
newLi.innerText = name + " " + "(" + position + ")" + " " + dif
newUl.appendChild(newLi)
}
result.appendChild(newUl)
}, function(status) {
alert('Something went wrong.');
});
}
var getJSON = function(url) {
return new Promise(function(resolve, reject) {
var xhr = new XMLHttpRequest();
xhr.open('get', url, true);
xhr.responseType = 'json';
xhr.onload = function() {
var status = xhr.status;
if (status == 200) {
resolve(xhr.response);
} else {
reject(status);
}
};
xhr.send();
});
};
// Convert Degress to Radians
function Deg2Rad(deg) {
return deg * Math.PI / 180;
}
function PythagorasEquirectangular(lat1, lon1, lat2, lon2) {
lat1 = Deg2Rad(lat1);
lat2 = Deg2Rad(lat2);
lon1 = Deg2Rad(lon1);
lon2 = Deg2Rad(lon2);
var R = 6371; // km
var x = (lon2 - lon1) * Math.cos((lat1 + lat2) / 2);
var y = (lat2 - lat1);
var d = Math.sqrt(x * x + y * y) * R;
return d;
}
output.innerHTML = "<p>Locating…</p>";
navigator.geolocation.getCurrentPosition(success, error);
}
geoFindMe();
</script-->
</body>
</html>