Skip to content

apimatic/google-maps-dotnet-v2-sdk

Repository files navigation

Getting Started with GoogleMapsPlatform

API Specification for Google Maps Platform.


Installation

Install this SDK into your application by adding a project reference to the SDK.

dotnet add reference <path-to-sdk>\GoogleMapsPlatform.csproj

Usage

using GoogleMapsPlatform;
using GoogleMapsPlatform.Models;

string key = "1POdFZRZbvb...qqillRxMr2z";
GoogleMapsPlatformClient client = new GoogleMapsPlatformClient(new HttpClient(), new GoogleMapsPlatformClientOptions(), key);

try
{
    string location = "39.6034810,-119.6822510";
    decimal timestamp = 1733428634;
    TimeZoneResponse response = await client.Timezone(Language.En, location, timestamp);
    // TODO: decide what happens when api call is successfully completed
}
catch (SdkException<VoidErrorResponse> ex)
{
    // TODO: decide what happens when api call is resulted in an error status code
}

Client Options

The following options are configurable in your client:

Parameter Type Description
RetryOptions RetryOptions The Retry options for the API Calls

Retry Options

The following fields are available in RetryOptions:

Parameter Type Description
Timeout TimeSpan Per-request timeout; cancels requests exceeding this duration.
Default: 100s
StatusCodesToRetry IReadOnlyList<HttpStatusCode> HTTP status codes that trigger a retry.
Default: 408, 429, 500, 502, 503, 504
HttpMethodsToRetry IReadOnlyList<HttpMethod> HTTP methods eligible for retry.
Default: GET, HEAD, PUT, OPTIONS
MaxRetries int Maximum number of retry attempts.
Default: 3
Delay TimeSpan Base delay before each retry attempt.
Default: 1s
BackOffFactor int Multiplier for exponential backoff (e.g., 2 doubles each attempt's delay).
Default: 2
UseExponentialBackoff bool Enables exponential backoff; when false, uses constant delay.
Default: true
MaxJitter TimeSpan Maximum random jitter added to delay to reduce contention.
Default: 500ms
OnRetry Action<Exception, TimeSpan, int> Callback invoked on each retry with the error/result, applied delay, and attempt number.
Default: null

Retries and BackOff

using GoogleMapsPlatform;
using GoogleMapsPlatform.Models;

GoogleMapsPlatformClientOptions options =
    new GoogleMapsPlatformClientOptions
    {
        RetryOptions = GoogleMapsPlatform.Core.Configuration.RetryOptions.Default() with
        {
            MaxRetries = 5,
            Delay = TimeSpan.FromSeconds(2)
        }
    };
    

GoogleMapsPlatformClient client = new GoogleMapsPlatformClient(new HttpClient(), options, key);

// Make any API Call with HttpMethod GET
string location = "39.6034810,-119.6822510";
decimal timestamp = 1733428634;
TimeZoneResponse response = await client.Timezone(Language.En, location, timestamp);

API Key Authentication via Query Parameter

using GoogleMapsPlatform;
using GoogleMapsPlatform.Models;

// Initialize Client with ApiKey
string key = "1POdFZRZbvb...qqillRxMr2z";
GoogleMapsPlatformClient client = new GoogleMapsPlatformClient(new HttpClient(), new GoogleMapsPlatformClientOptions(), key);


// Make an API Call that requires authentication
string location = "39.6034810,-119.6822510";
decimal timestamp = 1733428634;
TimeZoneResponse response = await client.Timezone(Language.En, location, timestamp);

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages