Bonjour,

En pleine création d'une petite application mobile sous Android, pour la géolocalisation de points remarquables avec prise de photos. J'utilise Cordova et Leaflet. Pour la gestion de mes erreurs dans mon script JavaScript j'ai les constantes : PERMISSION_DENIED, TIMEOUT, POSITION_UNAVAILABLE et UNKNOW_ERROR. Or, pour les tester rapidement j'éteins mon GPS de mon smartphone sur lequel je teste l'application hors l'alerte est celle de la constante TIMEOUT pas celle PERMISSION_DENIED. En effet, l'alerte est toujours celle de TIMEOUT.

Voici mon code ci-dessous :
Comment tester autrement la gestion de mes erreurs de mon code ?

Cordialement,
Code html : Sélectionner tout - Visualiser dans une fenêtre à part
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
<html>
    <head>
        <meta charset="utf-8" />
        <meta name="format-detection" content="telephone=no" />
        <meta name="msapplication-tap-highlight" content="no" />
        <!-- WARNING: for iOS 7, remove the width=device-width and height=device-height attributes. See https://issues.apache.org/jira/browse/CB-4323 -->
        <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
        <title>AÏGO</title>
		<link rel="stylesheet" type="text/css" href="css/index.css" />
		<link rel="stylesheet" href="css/leaflet.css" />
		<script src="js/leaflet.js"></script>
		<script type="text/javascript" src="cordova.js"></script>
		<script type="text/javascript" src="js/capture.js"></script>
		<link rel="stylesheet" href="jquery/jquery.mobile-1.4.5.min.css">
		<script src="jquery/jquery-1.11.3.min.js"></script>
		<script src="jquery/jquery.mobile-1.4.5.min.js"></script>
		<script type="text/javascript" src="js/date_heure.js"></script>
</head>
 
 
 
<body onLoad="ready">
 
 
 
	<div data-role="page" id="index">
		<div data-theme="b" data-role="header">
			 <h1>Carte</h1>
        </div>
 
		<div data-role="content">
			<div id="map" ></div>
				<div data-role="controlgroup">
					<a data-role="button" data-icon="star" onclick='test()'>Point</a>
					<a href="#infopoint" onclick='Picture();' data-role="button" data-icon="star">Photo</a>
				</div>
		</div>
	</div>
 
	<script>
                var map = L.map('map');
 
                L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
                        maxZoom: 18,
                        minZoom: 6,
                        attribution: 'Map data © ; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>' +
                                '<a href="http://creativecommons.org/licenses/by-sa/2.0/"></a>',
                        id: 'examples.map-i875mjb7'
                        
                }).addTo(map);
 
                map.locate({setView: true, maxZoom: 18});
                
                watchID = navigator.geolocation.watchPosition(onSuccess,error,{ maximumAge: 30000, timeout: 10000, enableHighAccuracy: true });
                
                                
                function test() {       
                        map.panTo([x,y], 12);
                        var marker = L.marker([x , y]).addTo(map);
                }
                
                var popup = L.popup();
                
                function onMapClick(e) {
                        popup.setLatLng(e.latlng).setContent(e.latlng.toString()).openOn(map);
                }
 
                map.on('click', onMapClick);
                
                function onSuccess(position) {
                        //alert('Latitude : '  + position.coords.latitude      +
            //      '\nLongitude : ' + position.coords.longitude);
                
                        x = position.coords.latitude;
                        y = position.coords.longitude;
                
                        document.getElementById("coor_x").value = x;
                        document.getElementById("coor_y").value = y;
                }
                
                function clearWatch() {
                        if (watchID != null) {navigator.geolocation.clearWatch(watchID); watchID = null;}
                }
                
                function error(erreur) {
                var info = "Erreur lors de la géolocalisation : ";
                                switch (erreur.code) {
                                        case error.PERMISSION_DENIED:
                                                alert ('Vous n’avez pas donné la permission');
                                break;
                                        case erreur.TIMEOUT :
                                                alert ('Délais de recherche dépassé');                               
                                break;
                                        case error.POSITION_UNAVAILABLE:
                                                alert ('La position n’a pu être déterminée');
                                break;
                                        case error.UNKNOW_ERROR:
                                                alert ('Erreur inconnue');
                                break;
                                }
                }
                document.getElementById("infoposition").innerHTML = info;
 
                </script>
 
		<script>
                
        function ready () {
                        document.addEventListener("deviceready", onDeviceReady, false);
                }
                
                function onDeviceReady() {
                        console.log(navigator.camera);
                }
                
                function   Picture (){
                //sourceType: Camera.PictureSourceType.SAVEDPHOTOALBUM
                        navigator.camera.getPicture(onSuccess, onFail, {quality: 70, destinationType: Camera.DestinationType.FILE_URI, targetWidth: 200, targetHeight: 200, mediaType: Camera.MediaType.ALLMEDIA});
                //alert('photo');
                }
 
                function onSuccess(imageURI) {
                        var image = document.getElementById('image')
                        image.src = imageURI;
                        image.style.display = 'block';
                }
 
                function onFail(message) {
                        alert('Failed because: ' + message);
                }
                
                
        </script>
 
 
	<div data-role="page" id="infopoint">
		<div data-theme="b" data-role="header">
			 <h1>Information</h1>
        </div>
			<div data-role="content">
				<div>
					<center>
							<br>
			<label>Date et heure : </label><span id="date_heure"></span>
            <script type="text/javascript">window.onload = date_heure('date_heure');</script> <!--Eventuellement à automatiser et heure -->
							<br/>
							<br/>
					<label>ASA : </label><select><option>ASA 1</option>
										 <option>ASA 2</option>
										 <option>ASA 3</option>
										 <option>ASA 4</option>
								 </select> 					<!-- Récupérer à partir de l'identification -->
							<br/>
							<br/>					
					<label>Nom : </label><input type="text"/> <!--De la personne faisant l'acquisition-->
							<br/>
							<br/>
					<label>Prénom : </label><input type="text"/> <!--De la personne faisant l'acquisition-->
							<br/>
							<br/>
					<label>Commune : </label><select><option>Arles</option>
										<option>Aureille</option>
										<option>Eygières</option>
										<option>Fonveille</option>
										<option>Istres</option>
										<option>Lamanon</option>
 
										<option>Le Paradou</option>
										<option>Mauriès</option> 
										<option>Maussane les Alpilles</option>
										<option>Miramas</option>
										<option>St Martin de Crau</option>
								 </select> <!-- -->
							<br/>
							<br/>
					<label>Intérêt : </label><select><option>Fuite</option>
										<option>Bouché</option>
										<option>Végétation</option>
								 </select> <!--Eventuellement à automatiser et heure-->
							<br/>
							<br/>
					<label>Id du point : </label><input type="text"/> <!--Obligatoire / Nom donnée au point-->
							<br/>
							<br/>
					<label>Latitude : </label><input type="text"/> <!-- Récupérer à partir du GPS page précédente -->
							<br/>
							<br/>
					<label>Longitude : </label><input type="text"/> <!-- Récupérer à partir du GPS page précédente -->
							<br/>
							<br/>
					<label>Commentaire : </label><textarea rows="4" cols="25">Commentaire ici </textarea> <!--Obligatoire-->
							<br/>
							<br/>
					<a href="map.html" data-role="button" data-icon="star" >Valider</a>
						<center>
				</div>
			</div>
 
	</div>
	</center>
 
 
 
</body>
</html>