My favorites | Sign in
Project Home Downloads Wiki Issues Source
READ-ONLY: This project has been archived. For more information see this post.
Search
for
  Advanced search   Search tips   Subscriptions

Issue 2 attachment: StatusAndAddress.patch (17.1 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
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
Index: src/Core/Address.cs
===================================================================
--- src/Core/Address.cs (revision 31)
+++ src/Core/Address.cs (working copy)
@@ -5,6 +5,7 @@
{
public class Address
{
+ private string formattedAddress;
private string street;
private string city;
private string state;
@@ -13,6 +14,12 @@
private Location coordinates;
private AddressAccuracy accuracy;

+ public string FormattedAddress
+ {
+ get { return formattedAddress ?? ""; }
+ set { formattedAddress = value; }
+ }
+
public string Street
{
get { return street ?? ""; }
Index: src/Core/AddressAccuracy.cs
===================================================================
--- src/Core/AddressAccuracy.cs (revision 31)
+++ src/Core/AddressAccuracy.cs (working copy)
@@ -4,12 +4,39 @@
{
public enum AddressAccuracy
{
- Unknown,
- CountryLevel,
- StateLevel,
- CityLevel,
- PostalCodeLevel,
- StreetLevel,
- AddressLevel
+ /// <summary>
+ /// Unknown accuracy.
+ /// </summary>
+ Unknown = 0,
+
+ /// <summary>
+ /// Country level accuracy.
+ /// </summary>
+ CountryLevel = 1,
+
+ /// <summary>
+ /// Region (state, province, prefecture, etc.) level accuracy.
+ /// </summary>
+ StateLevel = 2,
+
+ /// <summary>
+ /// Town (city, village) level accuracy.
+ /// </summary>
+ CityLevel = 4,
+
+ /// <summary>
+ /// Post code (zip code) level accuracy.
+ /// </summary>
+ PostalCodeLevel = 5,
+
+ /// <summary>
+ /// Street level accuracy.
+ /// </summary>
+ StreetLevel = 6,
+
+ /// <summary>
+ /// Address level accuracy.
+ /// </summary>
+ AddressLevel = 8
}
}
Index: src/Services/Google/GoogleAddressAccuracy.cs
===================================================================
--- src/Services/Google/GoogleAddressAccuracy.cs (revision 31)
+++ src/Services/Google/GoogleAddressAccuracy.cs (working copy)
@@ -2,16 +2,56 @@

namespace GeoCoding.Services.Google
{
- public enum GoogleAddressAccuracy
+ public enum GoogleAddressAccuracy : int
{
- UnknownLocation,
- CountryLevel,
- RegionLevel,
- SubRegionLevel,
- TownLevel,
- ZipCodeLevel,
- StreetLevel,
- IntersectionLevel,
- AddressLevel
+ /// <summary>
+ /// Unknown accuracy.
+ /// </summary>
+ UnknownLocation = 0,
+
+ /// <summary>
+ /// Country level accuracy.
+ /// </summary>
+ CountryLevel = 1,
+
+ /// <summary>
+ /// Region (state, province, prefecture, etc.) level accuracy.
+ /// </summary>
+ RegionLevel = 2,
+
+ /// <summary>
+ /// Sub-region (county, municipality, etc.) level accuracy.
+ /// </summary>
+ SubRegionLevel = 3,
+
+ /// <summary>
+ /// Town (city, village) level accuracy.
+ /// </summary>
+ TownLevel = 4,
+
+ /// <summary>
+ /// Post code (zip code) level accuracy.
+ /// </summary>
+ ZipCodeLevel = 5,
+
+ /// <summary>
+ /// Street level accuracy.
+ /// </summary>
+ StreetLevel = 6,
+
+ /// <summary>
+ /// Intersection level accuracy.
+ /// </summary>
+ IntersectionLevel = 7,
+
+ /// <summary>
+ /// Address level accuracy.
+ /// </summary>
+ AddressLevel = 8,
+
+ /// <summary>
+ /// Premise (building name, property name, shopping center, etc.) level accuracy.
+ /// </summary>
+ PremiseLevel = 9
}
}
Index: src/Services/Google/GoogleGeoCoder.cs
===================================================================
--- src/Services/Google/GoogleGeoCoder.cs (revision 31)
+++ src/Services/Google/GoogleGeoCoder.cs (working copy)
@@ -90,21 +90,21 @@
string zip = EvaluateXPath("string(//adr:PostalCodeNumber)", nav);
string[] coordinates = EvaluateXPath("string(//kml:Point/kml:coordinates)", nav).Split(',');

- var addr = new Address() { Street = street, City = city, State = state, PostalCode = zip, Country = country };
+ var addr = new Address() { FormattedAddress = formattedAddress, Street = street, City = city, State = state, PostalCode = zip, Country = country };
addr.ChangeLocation(FromCoordinates(coordinates), MapAccuracy(accuracy));
return addr;
}

- private Address[] ProcessWebResponse(WebResponse response)
+ private Address[] ProcessWebResponse(WebResponse response, out int status)
{
XPathDocument xmlDoc = LoadXmlResponse(response);
XPathNavigator nav = xmlDoc.CreateNavigator();
namespaceManager = CreateXmlNamespaceManager(nav);

- GoogleStatusCode status = (GoogleStatusCode)int.Parse(EvaluateXPath("string(kml:kml/kml:Response/kml:Status/kml:code)", nav));
+ status = int.Parse(EvaluateXPath("string(kml:kml/kml:Response/kml:Status/kml:code)", nav));

List<Address> addresses = new List<Address>();
- if (status == GoogleStatusCode.Success)
+ if ((GoogleStatusCode)status == GoogleStatusCode.Success)
{
XPathExpression exp = nav.Compile("kml:kml/kml:Response/kml:Placemark");
exp.SetContext(namespaceManager);
@@ -134,6 +134,7 @@
case GoogleAddressAccuracy.StreetLevel: return AddressAccuracy.StreetLevel;
case GoogleAddressAccuracy.IntersectionLevel: return AddressAccuracy.StreetLevel;
case GoogleAddressAccuracy.AddressLevel: return AddressAccuracy.AddressLevel;
+ case GoogleAddressAccuracy.PremiseLevel: return AddressAccuracy.AddressLevel;
default: return AddressAccuracy.Unknown;
}
}
@@ -148,19 +149,29 @@

public Address[] GeoCode(string address)
{
+ int status;
+ return GeoCode(address, out status);
+ }
+ public Address[] GeoCode(string address, out int status)
+ {
if (String.IsNullOrEmpty(address)) throw new ArgumentNullException("address");

HttpWebRequest request = BuildWebRequest(address);
using (WebResponse response = request.GetResponse())
{
- return ProcessWebResponse(response);
+ return ProcessWebResponse(response, out status);
}
}

public Address[] GeoCode(string street, string city, string state, string postalCode, string country)
{
+ int status;
+ return GeoCode(street, city, state, postalCode, country, out status);
+ }
+ public Address[] GeoCode(string street, string city, string state, string postalCode, string country, out int status)
+ {
string address = String.Format("{0} {1}, {2} {3}, {4}", street, city, state, postalCode, country);
- return GeoCode(address);
+ return GeoCode(address, out status);
}

public override string ToString()
Index: src/Services/Google/GoogleStatusCode.cs
===================================================================
--- src/Services/Google/GoogleStatusCode.cs (revision 31)
+++ src/Services/Google/GoogleStatusCode.cs (working copy)
@@ -2,13 +2,43 @@

namespace GeoCoding.Services.Google
{
- public enum GoogleStatusCode
+ public enum GoogleStatusCode : int
{
+ /// <summary>
+ /// No errors occurred; the address was successfully parsed and its geocode was returned.
+ /// </summary>
Success = 200,
+
+ /// <summary>
+ /// A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is unknown.
+ /// </summary>
ServerError = 500,
+
+ /// <summary>
+ /// An empty address was specified in the HTTP q parameter.
+ /// </summary>
MissingAddress = 601,
+
+ /// <summary>
+ /// No corresponding geographic location could be found for the specified address, possibly because the address is relatively new, or because it may be incorrect.
+ /// </summary>
UnknownAddress = 602,
+
+ /// <summary>
+ /// The geocode for the given address or the route for the given directions query cannot be returned due to legal or contractual reasons.
+ /// </summary>
UnavailableAddress = 603,
- BadKey = 610
+
+ /// <summary>
+ /// The given key is either invalid or does not match the domain for which it was given.
+ /// </summary>
+ BadKey = 610,
+
+ /// <summary>
+ /// The given key has gone over the requests limit in the 24 hour period or has submitted too
+ /// many requests in too short a period of time. If you're sending multiple requests in parallel
+ /// or in a tight loop, use a timer or pause in your code to make sure you don't send the requests too quickly.
+ /// </summary>
+ TooManyQueries = 620
}
}
Index: src/Services/IGeoCoder.cs
===================================================================
--- src/Services/IGeoCoder.cs (revision 31)
+++ src/Services/IGeoCoder.cs (working copy)
@@ -5,6 +5,9 @@
public interface IGeoCoder
{
Address[] GeoCode(string address);
+ Address[] GeoCode(string address, out int status);
+
Address[] GeoCode(string street, string city, string state, string postalCode, string country);
+ Address[] GeoCode(string street, string city, string state, string postalCode, string country, out int status);
}
}
Index: src/Services/Services.csproj
===================================================================
--- src/Services/Services.csproj (revision 31)
+++ src/Services/Services.csproj (working copy)
@@ -70,7 +70,9 @@
</Compile>
<Compile Include="VirtualEarth\VirtualEarthGeoCoder.cs" />
<Compile Include="VirtualEarth\VirtualEarthServiceFactory.cs" />
+ <Compile Include="VirtualEarth\VirtualEarthStatusCode.cs" />
<Compile Include="Yahoo\YahooGeoCoder.cs" />
+ <Compile Include="Yahoo\YahooStatusCode.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Core\Core.csproj">
Index: src/Services/VirtualEarth/VirtualEarthGeoCoder.cs
===================================================================
--- src/Services/VirtualEarth/VirtualEarthGeoCoder.cs (revision 31)
+++ src/Services/VirtualEarth/VirtualEarthGeoCoder.cs (working copy)
@@ -84,18 +84,39 @@
return address;
}

- public GeoAddress[] GeoCode(string address)
+ public GeoAddress[] GeoCode(string address)
+ {
+ int status;
+ return GeoCode(address, out status);
+ }
+ public GeoAddress[] GeoCode(string address, out int status)
{
string token = Token();
var request = new GeocodeRequest() { Query = address, Credentials = new Credentials() { Token = token } };

var response = geocodeService.Geocode(request);
+
+ // Get the status
+ switch (response.ResponseSummary.StatusCode)
+ {
+ case ResponseStatusCode.Success: status = (int)VirtualEarthStatusCode.Success; break;
+ case ResponseStatusCode.ServerError: status = (int)VirtualEarthStatusCode.ServerError; break;
+
+ case ResponseStatusCode.BadRequest:
+ default: status = (int)VirtualEarthStatusCode.BadRequest; break;
+ }
+
return response.Results.Select(r => AddressFromVirtualEarth(r)).ToArray();
}

- public GeoAddress[] GeoCode(string street, string city, string state, string postalCode, string country)
+ public GeoAddress[] GeoCode(string street, string city, string state, string postalCode, string country)
+ {
+ int status;
+ return GeoCode(street, city, state, postalCode, country, out status);
+ }
+ public GeoAddress[] GeoCode(string street, string city, string state, string postalCode, string country, out int status)
{
- return GeoCode(street + " " + city + ", " + state + " " + postalCode + " " + country);
+ return GeoCode(street + " " + city + ", " + state + " " + postalCode + " " + country, out status);
}

public void Dispose()
Index: src/Services/VirtualEarth/VirtualEarthStatusCode.cs
===================================================================
--- src/Services/VirtualEarth/VirtualEarthStatusCode.cs (revision 0)
+++ src/Services/VirtualEarth/VirtualEarthStatusCode.cs (revision 0)
@@ -0,0 +1,25 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace GeoCoding.Services.VirtualEarth
+{
+ public enum VirtualEarthStatusCode
+ {
+ /// <summary>
+ /// The service request was successful and results were returned.
+ /// </summary>
+ Success,
+
+ /// <summary>
+ /// The service request was malformed and results could not be returned.
+ /// </summary>
+ BadRequest,
+
+ /// <summary>
+ /// An error occurred while the request was being processed.
+ /// </summary>
+ ServerError
+ }
+}
Index: src/Services/Yahoo/YahooGeoCoder.cs
===================================================================
--- src/Services/Yahoo/YahooGeoCoder.cs (revision 31)
+++ src/Services/Yahoo/YahooGeoCoder.cs (working copy)
@@ -134,12 +134,13 @@
return false;
}

- private Address[] GeoCode(HttpWebRequest request)
+ private Address[] GeoCode(HttpWebRequest request, out int status)
{
try
{
- using (WebResponse response = request.GetResponse())
+ using (var response = (HttpWebResponse)request.GetResponse())
{
+ status = (int)response.StatusCode;
return ProcessWebResponse(response);
}
}
@@ -147,23 +148,35 @@
{
if (!HandleWebException(ex))
throw;
+
+ status = (int)YahooStatusCode.BadRequest;
return new Address[0];
}
}

public Address[] GeoCode(string address)
{
+ int status;
+ return GeoCode(address, out status);
+ }
+ public Address[] GeoCode(string address, out int status)
+ {
if (String.IsNullOrEmpty(address)) throw new ArgumentNullException("address");

HttpWebRequest request = BuildWebRequest(address);
- return GeoCode(request);
+ return GeoCode(request, out status);
}

public Address[] GeoCode(string street, string city, string state, string postalCode, string country)
{
+ int status;
+ return GeoCode(street, city, state, postalCode, country, out status);
+ }
+ public Address[] GeoCode(string street, string city, string state, string postalCode, string country, out int status)
+ {
//ignoring the country parameter since yahoo doesn't accept it
HttpWebRequest request = BuildWebRequest(street, city, state, postalCode);
- return GeoCode(request);
+ return GeoCode(request, out status);
}

public override string ToString()
Index: src/Services/Yahoo/YahooStatusCode.cs
===================================================================
--- src/Services/Yahoo/YahooStatusCode.cs (revision 0)
+++ src/Services/Yahoo/YahooStatusCode.cs (revision 0)
@@ -0,0 +1,29 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace GeoCoding.Services.Yahoo
+{
+ public enum YahooStatusCode
+ {
+ Success = 200,
+
+ /// <summary>
+ /// Bad request. The parameters passed to the service did not match as expected. The Message should tell you what was missing or incorrect.
+ /// </summary>
+ BadRequest = 400,
+
+ /// <summary>
+ /// Forbidden. You do not have permission to access this resource, or are over your rate limit.
+ /// The Geocoding service is limited to 5,000 queries per IP address per day (2009-11-10)
+ /// See: http://developer.yahoo.com/search/rate.html
+ /// </summary>
+ Forbidded = 403,
+
+ /// <summary>
+ /// Service unavailable. An internal problem prevented us from returning data to you.
+ /// </summary>
+ ServiceUnavailable = 503
+ }
+}
Powered by Google Project Hosting