Stay organized with collections Save and categorize content based on your preferences.
This page has examples of how to use the Address Validation API client libraries to call the following services:
Install the client librariesSee Address Validation API client libraries for installation instructions.
AuthenticationWhen you use client libraries, you use Application Default Credentials (ADC) to authenticate. For information about setting up ADC, see Provide credentials for Application Default Credentials. For information about using ADC with client libraries, see Authenticate using client libraries .
You can also use API keys to authenticate to the client libraries, for example:
using Google.Maps.AddressValidation.V1;
using Google.Api.Gax.Grpc;
using Grpc.Core;
...
// Create settings to pass the API key as a header in every request.
var apiHeader = CallSettings.FromHeader("X-Goog-Api-Key", "API_KEY");
var defaultSettings = AddressValidationSettings.GetDefault();
var settings = new AddressValidationSettings
{
ValidateAddressSettings = defaultSettings.ValidateAddressSettings.MergedWith(apiHeader),
ProvideValidationFeedbackSettings = defaultSettings.ProvideValidationFeedbackSettings.MergedWith(apiHeader)
};
// Create a client builder with the custom settings.
AddressValidationClientBuilder builder = new AddressValidationClientBuilder
{
Settings = settings,
// Use SslCredentials to create a secure channel for API key authentication.
ChannelCredentials = new SslCredentials()
};
AddressValidationClient client = await builder.BuildAsync();
When you use API keys in your applications, make sure that they are kept secure during both storage and transmission. Publicly exposing your API keys can lead to unexpected charges on your account.
The examples on this page use Application Default Credentials.
Examples validateAddressThe following is an example of how to call validateAddress
using the .NET client library.
using Google.Maps.AddressValidation.V1;
using Google.Type;
...
private static async Task CallAddressValidation()
{
// Create the Address Validation Client
AddressValidationClient client = await AddressValidationClient.CreateAsync();
// Define the request with the address to be validated
var request = new ValidateAddressRequest
{
Address = new PostalAddress
{
RegionCode = "US",
LanguageCode = "en",
PostalCode = "94043",
AdministrativeArea = "CA",
Locality = "Mountain View",
AddressLines = { "1600 Amphitheatre Parkway" }
}
};
try
{
// Call the API asynchronously
ValidateAddressResponse response = await client.ValidateAddressAsync(request);
// Process the results
Console.WriteLine($"Validation Granularity: {response.Result.Verdict.ValidationGranularity}");
Console.WriteLine($"Formatted Address: {response.Result.Address.FormattedAddress}");
Console.WriteLine($"Response ID: {response.ResponseId}");
}
catch (Exception ex)
{
Console.WriteLine($"An error occurred: {ex.Message}");
}
}
Define a PostalAddress
object with componentized address fields like RegionCode
, Locality
, and AddressLines
. When building the example request, this PostalAddress
is used to create a ValidateAddressRequest
. The ValidateAddressAsync
method is then called to make the request, and details from the response like the ValidationGranularity
and the FormattedAddress
are output.
The following is an example of how to call provideValidationFeedback
using the .NET client library.
using Google.Maps.AddressValidation.V1;
...
private static async Task ProvideValidationFeedback()
{
AddressValidationClient client = await AddressValidationClient.CreateAsync();
var feedbackRequest = new ProvideValidationFeedbackRequest
{
// Set the conclusion based on the user's choice. This exampels uses ValidatedVersionUsed
Conclusion = ProvideValidationFeedbackRequest.Types.ValidationConclusion.ValidatedVersionUsed,
// Provide the ID from the validation response.
ResponseId = "Response_ID"
};
try
{
Console.WriteLine("Sending feedback to the API");
// This call returns an empty response on success.
await client.ProvideValidationFeedbackAsync(feedbackRequest);
Console.WriteLine(" -> Feedback sent successfully!");
}
catch (Exception ex)
{
Console.WriteLine($"An error occurred: {ex.Message}");
}
}
Create a ProvideValidationFeedbackRequest
to send information about the final outcome of an address validation sequence. The request requires a Conclusion
to specify whether the user's original address or Google's validated address was used. Crucially, you must also provide the ResponseId
obtained from the initial ValidateAddressResponse
to link the feedback to the correct transaction.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-07-09 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-07-09 UTC."],[],[]]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4