.NET Client for Google Maps APIs Services is a .NET Client library for the following Google Maps APIs:
- .NET 3.5 or later.
- A Google Maps API key.
Each Google Maps Web Service request requires an API key or client ID. API keys are freely available with a Google Account at https://developers.google.com/console. The type of API key you need is a Server key.
To get an API key:
- Visit https://developers.google.com/console and log in with a Google Account.
- Select one of your existing projects, or create a new project.
- Enable the API(s) you want to use. The .NET Client for Google Maps Services
accesses the following APIs:
- Geocoding API
- Create a new Server key.
- If you'd like to restrict requests to a specific IP address, do so now.
For guided help, follow the instructions for the [Directions API][directions-key]. You only need one API key, but remember to enable all the APIs you need. For even more information, see the guide to [API keys][apikey].
Important: This key should be kept secret on your server.
To install Google Maps API Services Client Library, run the following command in the Package Manager Console
Install-Package Google.Maps.Client
GeocodingRequest request = new GeocodingRequest("plovdiv bulgaria");
GeocodingResponse response = request.GetResponse();
// GeocodingResponse response = request.GetResponseAsync();
LatLng location = response.Results[0].Geometry.Location;
double latitude = location.Latitude;
double longitude = location.Longitude;
// TODO use latitude/longitude values}}
GeocodingRequest request = new GeocodingRequest(42.1438409, 24.7495615);
GeocodingResponse response = request.GetResponse();
string address = response.Results[0].FormattedAddress;
// TODO use address values
Builds for all .NET frameworks support async request/response now.
// NET35 & NET40 async get request
GeocodingRequest request = new GeocodingRequest("plovdiv bulgaria");
GeocodingResponse response = request.GetResponseAsync();
// NET45 async get request
GeocodingRequest request = new GeocodingRequest("plovdiv bulgaria");
GeocodingResponse response = await request.GetResponseAsync();
MapsApiContext was added to share common settings between Google Maps API requests.
New instance of context can be created with the seetings to use, or can be loaded from config app settings (app.config or web.config).
There is a default instance of the context (MapsApiContext.Default) which by default will try to load from config app settings or use default value per setting.
Default settings' values:
DefaultGeocodeApiUrl = "https://maps.google.com/maps/api/geocode/json?";
DefaultAutoRetry = true;
DefaultRetryDelay = 100;// in milliseconds
DefaultRetryTimes = 5;
A sample config app settings:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="GoogleMaps.ApiKey" value="API_KEY"/>
<!--next is optional, by default https://maps.google.com/maps/api/geocode/json? will be used-->
<add key="GoogleMaps.GeocodeApiUrl" value="API_URL"/>
<add key="GoogleMaps.AutoRetry" value="true"/>
<add key="GoogleMaps.RetryDelay" value="100"/>
<add key="GoogleMaps.RetryTimes" value="5"/>
</appSettings>
</configuration>
When creating requests without an instance of MapsApiContext, default instance will be used.
Check out the contribution guidelines if you want to contribute to this project.
- Thanks to Rico Suter for TaskSynchronizationScope used to synchronize async code blocks