GoogleMapsApiServiceProxy¶
GoogleMapsApiServiceProxy implements IGoogleMapsApiServiceProxy as a hand-rolled REST/XML client over System.Net.WebRequest — the only wrapper in this library that is not SOAP — resolving its base URI and API key from configuration and exposing both a strict single-pair method that throws on failure and tolerant multi-address methods that report zero-mile results instead. It is constructor-injected into SAIF.Services.Legal.Subpoenas.SubpoenaService.
Purpose¶
- Query the Google Distance Matrix API for driving distance/time between address pairs, with pipe-delimited, non-URL-encoded addresses and a 5-second request timeout (WP-BR-021).
- Convert meters to miles using a fixed conversion factor, rounded to one decimal place (WP-BR-022).
- Report a structured
ErrorMessagefor a single-pair non-OK response, and a 0-mile result for a failing element within a multi-address query, rather than propagating either as an unhandled exception (WP-BR-023, WP-BR-024).
Context¶
- Namespace:
SAIF.Services.Web.Proxies - Assembly/package:
SAIF.Services.Web.Proxies(packaged inSAIF.SAIFCode.Core)
Public members¶
| Member | Signature | Purpose |
|---|---|---|
| Constructor | GoogleMapsApiServiceProxy(ILogService logService, IEnvironmentService environmentService) |
Guards both injected services, then reads googlemaps.apibaseuri and googlemaps.apikey via GetConfigSetting (WP-BR-001, WP-BR-020) |
GetDataBetweenTwoAddresses |
DistanceResults GetDataBetweenTwoAddresses(string origin, string destination) |
Returns a structured result with Miles, Distance, Time, and Seconds on an "OK" status, or an ErrorMessage otherwise (WP-BR-023); not part of IGoogleMapsApiServiceProxy |
GetMilesBetweenTwoAddresses |
decimal GetMilesBetweenTwoAddresses(string origin, string destination) |
Returns the driving distance in miles between one origin and one destination; any parse failure throws a generic mileage-error exception |
GetMilesFromManyToOneAddress |
IList<decimal> GetMilesFromManyToOneAddress(IList<string> origins, string destination) |
Returns miles from each origin to a single destination; a failing element yields 0 (WP-BR-024) |
GetMilesFromOneToManyAddresses |
IList<decimal> GetMilesFromOneToManyAddresses(string origin, IList<string> destinations) |
Returns miles from a single origin to each destination; a failing element yields 0 (WP-BR-024) |
GetMilesBetweenMultipleAddresses |
IList<decimal> GetMilesBetweenMultipleAddresses(IList<string> origins, IList<string> destinations) |
Returns pairwise (diagonal) miles for equal-length lists, throwing before any query if the counts differ (WP-BR-025) |
Behavioral notes¶
- The private
QueryGoogleApilogs anyWebRequest/parsing exception viaILogService.LogException("GoogleMapsApiServiceProxy", "QueryGoogleApi", "WebRequest", e), then rethrowsnew Exception(e.Message), losing the original exception type and stack trace*. - The
WebResponseand its stream are not disposed after use*. - Addresses are not URL-encoded before being placed in the query string, which risks malformed requests or parameter injection from address text containing reserved characters*.
- The Google API key is sent in the request query string rather than a header, so it can appear in proxy or server access logs* (see Configuration).
Constraints and usage notes¶
- Hard-coded, non-configurable values: the
distancematrix/xml?units=imperial&language=enpath, a 5000 msWebRequest.Timeout, and the1609.34meters-per-mile conversion factor.
Note: Statements marked with * were inferred from code structure, naming conventions, or contextual evidence where direct confirmation was not available in source artifacts.
Sources¶
Services/SAIF.Services.Web.Proxies/GoogleMapsApiServiceProxy.cs