-
Notifications
You must be signed in to change notification settings - Fork 0
/
10km.html
161 lines (156 loc) · 4.76 KB
/
10km.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
<!DOCTYPE html>
<!--[if IE 8]> <html lang="en" class="ie8"> <![endif]-->
<!--[if !IE]><!-->
<html lang="en">
<!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=1" />
<title>10 Km</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAFsYKoqX2pkuRyk6nunqW8P0b8DC7BX9s&libraries=places"></script>
<style>
header, footer {
max-width: 400px;
width:100%;
margin: 0 auto;
font-family: 'Helvetica Neue',sans-serif !important;
font-size: 14px !important;
text-align: center;
z-index:1;
background-color: rgb(255,255,255,0.5);
left: 0;
right: 0;
}
header form {
margin: 0px;
margin-bottom: 5px;
padding: 5px;
background-color: white;
}
header {
position: fixed;
top: 0;
}
#address {
width: 100%;
max-width: 250px;
}
#map{
/*padding: 0;*/
padding-top: 45px;
height: 100vh;
width: 100%;
background-color: white;
}
</style>
</head>
<body>
<header>
<form>
<input type="text" id="address" placeholder="Entrez votre adresse"/>
<button class="btn" id="btn-location"><a href="javascript:;" onclick="getCurrentPosition()">Ma position</a></button>
</form>
</header>
<div id="map"></div>
<noscript>
<div id="page-container">
<div class="text-center p-t-30 p-b-20 bg-white">
<h4 class="m-t-20 text-default"><em>Cette page nécessite l'activation du javascript dans votre navigateur.</em></h4>
</div>
</div>
</noscript>
</body>
<script type="text/javascript">
function success(position){
refreshMap(position.coords.latitude,position.coords.longitude);
}
function error(error){
var info = 'Erreur de géolocalisation : ';
switch(error.code) {
case error.TIMEOUT:
info += 'Timeout !';
break;
case error.PERMISSION_DENIED:
info += 'Vous n’avez pas donné la permission';
break;
case error.POSITION_UNAVAILABLE:
info += 'La position n’a pu être déterminée';
break;
case error.UNKNOWN_ERROR:
info += 'Erreur inconnue';
break;
}
alert(info);
}
function getCurrentPosition(){
if(navigator.geolocation) {
document.getElementById("btn-location").disabled = true;
document.getElementById("btn-location").textContent = "recherche...";
navigator.geolocation.getCurrentPosition(success, error);
document.getElementById("btn-location").disabled = false;
document.getElementById("btn-location").textContent = "Ma position";
}
else{
alert('Ce navigateur ne supporte pas la géolocalisation');
}
}
function autocomplete(id) {
var element = document.getElementById(id);
if (element) {
var autocomplete = new google.maps.places.Autocomplete(element, {
// bounds: cityBounds,
strictBounds: true,
types: ['geocode'],
componentRestrictions: {country: 'fr'}
});
google.maps.event.addListener(autocomplete, 'place_changed', onAddressChanged);
google.maps.event.addDomListener(element, 'keydown', function(e) {
if (e.keyCode === 13) {
e.preventDefault();
}
});
}
}
function onAddressChanged() {
var place = this.getPlace();
if(place.geometry.location === undefined) return;
refreshMap(place.geometry.location.lat(),place.geometry.location.lng());
document.getElementById("address").value = "";
}
function refreshMap(lat, lng){
var options = {
zoom: 12,
center: new google.maps.LatLng(lat, lng),
// mapTypeId: 'satellite',
// scrollwheel: false
mapTypeControl: true,
mapTypeControlOptions: {
// style: google.maps.MapTypeControlStyle.DROPDOWN_MENU,
position: google.maps.ControlPosition.LEFT_BOTTOM
},
fullscreenControl: true,
fullscreenControlOptions: {
position: google.maps.ControlPosition.RIGHT_TOP
},
zoomControl: true,
zoomControlOptions: {
position: google.maps.ControlPosition.RIGHT_BOTTOM
},
scaleControl: true,
}
var map = new google.maps.Map(document.getElementById("map"), options);
var circle = new google.maps.Circle({ map: map, center: options.center, radius: 10000});
var marker = new google.maps.Marker({
position: options.center,
fontSize: 20,
map: map
});
}
refreshMap(44.8537161, -0.587332);
autocomplete('address');
</script>
</html>