Subversion Repositories eFlore/Applications.cel

Rev

Rev 258 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 258 Rev 266
Line 49... Line 49...
49
					} else {
49
					} else {
50
						final JSONValue responseValue = JSONParser
50
						final JSONValue responseValue = JSONParser
51
								.parse(response.getText());
51
								.parse(response.getText());
Line 52... Line 52...
52
 
52
 
-
 
53
						if (responseValue.isObject() != null) {
-
 
54
							EntiteGeographiqueObservation infos;
-
 
55
							String idLocalite = "";
-
 
56
							String nomCommune = "";
53
						if (responseValue.isObject() != null) {
57
							
-
 
58
							JSONObject resultat = responseValue.isObject();
-
 
59
							if(resultat != null && resultat.containsKey("geonames")) {
54
							JSONObject resultat = responseValue.isObject();
60
								if(resultat.get("geonames").isArray() != null) {
55
							JSONArray tableauCommune = resultat.get("geonames")
61
									JSONArray tableauCommune = resultat.get("geonames")
-
 
62
									.isArray();
-
 
63
									if(tableauCommune.get(0) != null) {
56
									.isArray();
64
										if(tableauCommune.get(0).isObject() != null) {
57
							JSONObject objetCommune = tableauCommune.get(0)
65
											JSONObject objetCommune = tableauCommune.get(0)
Line 58... Line 66...
58
									.isObject();
66
											.isObject();
59
 
-
 
60
							/*String valeurCommune = objetCommune.get("name")
-
 
61
									.isString().stringValue();
-
 
62
							r.rafraichir(valeurCommune, false);*/
67
											
63
							
-
 
64
							String pays = objetCommune.get("countryName").isString()
-
 
65
							.stringValue();
-
 
66
							
-
 
67
							if(!pays.equals("France")){
-
 
68
								r.rafraichir("Aucune commune française n'a été trouvée à cet emplacement", false);
-
 
69
								return;
-
 
70
							}
-
 
71
								
-
 
72
							Double newLng = objetCommune.get("lng").isNumber()
-
 
73
							.doubleValue();
-
 
74
							Double newLat = objetCommune.get("lat").isNumber()
68
											if(objetCommune.containsKey("name")) {
75
									.doubleValue();
69
												if(objetCommune.get("name").isString() != null)  {
-
 
70
													nomCommune = objetCommune.get(
-
 
71
													"name").isString().stringValue();
Line -... Line 72...
-
 
72
												}
-
 
73
											}
76
							String nomCommune = objetCommune.get(
74
											
77
									"name").isString().stringValue();
75
											if(objetCommune.containsKey("adminCode2")) {
-
 
76
												if(objetCommune.get("adminCode2").isString() != null)  {
-
 
77
													idLocalite = objetCommune.get(
-
 
78
													"adminCode2").isString().stringValue();
-
 
79
												}
-
 
80
											}
-
 
81
										}
Line 78... Line 82...
78
							
82
									}
-
 
83
								}
-
 
84
							}
Line 79... Line 85...
79
							String idLocalite = objetCommune.get(
85
							
80
							"adminCode2").isString().stringValue();
86
							infos = new EntiteGeographiqueObservation(idLocalite, nomCommune, null, null);
81
		
87
							infos.setLat(""+lat);
82
							Object[] infos = { lat, lng, idLocalite, nomCommune, newLat, newLng};
88
							infos.setLon(""+lng);
Line 124... Line 130...
124
						final JSONValue responseValue = JSONParser
130
						final JSONValue responseValue = JSONParser
125
								.parse(response.getText());
131
								.parse(response.getText());
Line 126... Line 132...
126
 
132
 
Line -... Line 133...
-
 
133
						if (responseValue.isObject() != null) {
-
 
134
							
-
 
135
							EntiteGeographiqueObservation infos;
-
 
136
							String idLocalite = "";
-
 
137
							String nomCommune = "";
-
 
138
							Double lng = 0.0;
127
						if (responseValue.isObject() != null) {
139
							Double lat = 0.0;
128
 
-
 
129
							JSONObject resultat = responseValue.isObject();
-
 
Line -... Line 140...
-
 
140
 
-
 
141
							JSONObject resultat = responseValue.isObject();
-
 
142
							
-
 
143
							if(resultat != null && resultat.containsKey("postalCodes")) {
130
							JSONArray tableauCommune = resultat.get(
144
								if(resultat.get("postalCodes").isArray() != null) {
-
 
145
									JSONArray tableauCommune = resultat.get("postalCodes")
131
									"postalCodes").isArray();
146
									.isArray();
132
 
147
									if(tableauCommune.get(0) != null) {
Line -... Line 148...
-
 
148
										if(tableauCommune.get(0).isObject() != null) {
133
							if (tableauCommune.get(0) != null) {
149
											JSONObject objetCommune = tableauCommune.get(0)
-
 
150
											.isObject();
134
								JSONObject objetCommune = tableauCommune.get(0)
151
											
-
 
152
											if(objetCommune.containsKey("lng")) {
-
 
153
												if(objetCommune.get("lng").isNumber() != null)  {
-
 
154
													lng = objetCommune.get(
135
										.isObject();
155
													"lng").isNumber().doubleValue();
136
 
156
												}
137
								Double lng = objetCommune.get("lng").isNumber()
157
											}
138
										.doubleValue();
158
											
-
 
159
											if(objetCommune.containsKey("lat")) {
-
 
160
												if(objetCommune.get("lat").isNumber() != null)  {
Line -... Line 161...
-
 
161
													lat = objetCommune.get(
-
 
162
													"lat").isNumber().doubleValue();
139
								Double lat = objetCommune.get("lat").isNumber()
163
												}
140
										.doubleValue();
164
											}
-
 
165
											
-
 
166
											if(objetCommune.containsKey("adminCode2")) {
Line -... Line 167...
-
 
167
												if(objetCommune.get("adminCode2").isString() != null)  {
-
 
168
													idLocalite = objetCommune.get(
-
 
169
													"adminCode2").isString().stringValue();
141
								String nomCommune = objetCommune.get(
170
												}
-
 
171
											}
-
 
172
											
-
 
173
											if(objetCommune.containsKey("placeName")) {
-
 
174
												if(objetCommune.get("placeName").isString() != null)  {
-
 
175
													nomCommune = objetCommune.get(
-
 
176
													"placeName").isString().stringValue();
Line -... Line 177...
-
 
177
												}
-
 
178
											}
-
 
179
										}
Line 142... Line 180...
142
										"placeName").isString().stringValue();
180
									}
143
								
181
								}
144
								String idLocalite = objetCommune.get(
182
							}
145
								"adminCode2").isString().stringValue();
183
							
146
 
-
 
147
								Object[] infos = { lat, lng, idLocalite, nomCommune};
184
							infos = new EntiteGeographiqueObservation(idLocalite, nomCommune, null, null);
148
 
185
							infos.setLat(""+lat);
149
 
186
							infos.setLon(""+lng);
150
								r.rafraichir(infos, false);
187
		
151
							}
188
							r.rafraichir(infos, false);