---
title: GoogleMapsApiServiceProxy
summary: API reference for GoogleMapsApiServiceProxy.
status: draft
owner: SAIF.Core Documentation Team
last_reviewed: 2026-09-24
library: SAIF.Services.Web.Proxies
reference_type: package
---

# 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](../../business-rules.md#wp-br-021-distance-queries-are-pipe-delimited-with-fixed-units-and-timeout)).
- Convert meters to miles using a fixed conversion factor, rounded to one decimal place ([WP-BR-022](../../business-rules.md#wp-br-022-miles-are-computed-from-meters-at-a-fixed-conversion-factor)).
- Report a structured `ErrorMessage` for 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](../../business-rules.md#wp-br-023-a-non-ok-element-status-sets-an-error-message-without-throwing), [WP-BR-024](../../business-rules.md#wp-br-024-a-failing-element-contributes-zero-miles)).

## Context
- Namespace: `SAIF.Services.Web.Proxies`
- Assembly/package: `SAIF.Services.Web.Proxies` (packaged in `SAIF.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](../../business-rules.md#wp-br-001-required-arguments-must-be-non-null-or-non-empty), [WP-BR-020](../../business-rules.md#wp-br-020-google-maps-base-uri-and-api-key-come-from-configuration)) |
| `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](../../business-rules.md#wp-br-023-a-non-ok-element-status-sets-an-error-message-without-throwing)); 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](../../business-rules.md#wp-br-024-a-failing-element-contributes-zero-miles)) |
| `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](../../business-rules.md#wp-br-024-a-failing-element-contributes-zero-miles)) |
| `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](../../business-rules.md#wp-br-025-pairwise-distance-queries-require-equal-counts)) |

## Behavioral notes
- The private `QueryGoogleApi` logs any `WebRequest`/parsing exception via `ILogService.LogException("GoogleMapsApiServiceProxy", "QueryGoogleApi", "WebRequest", e)`, then rethrows `new Exception(e.Message)`, losing the original exception type and stack trace*.
- The `WebResponse` and 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](../../configuration.md#secure-settings)).

## Constraints and usage notes
- Hard-coded, non-configurable values: the `distancematrix/xml?units=imperial&language=en` path, a 5000 ms `WebRequest.Timeout`, and the `1609.34` meters-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`
