scalefocus / google-maps-services

.NET client library for Google Maps API Web Services

Home Page:https://velyo.github.io/google-maps-services/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

.NET Client for Google Maps Services

Build status Build status Build status
NuGet
Stories in Ready Gitter

.NET Client for Google Maps APIs Services is a .NET Client library for the following Google Maps APIs:

Getting started

Requirements

  • .NET 3.5 or later.
  • A Google Maps API key.

API keys

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:

  1. Visit https://developers.google.com/console and log in with a Google Account.
  2. Select one of your existing projects, or create a new project.
  3. Enable the API(s) you want to use. The .NET Client for Google Maps Services accesses the following APIs:
    • Geocoding API
  4. Create a new Server key.
  5. 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.

Installation

To install Google Maps API Services Client Library, run the following command in the Package Manager Console

Install-Package Google.Maps.Client

Features

Geocoding

Address Geocoding Request

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}}

Reverse Geocoding Request

GeocodingRequest request = new GeocodingRequest(42.1438409, 24.7495615);
GeocodingResponse response = request.GetResponse();
string address = response.Results[0].FormattedAddress;
// TODO use address values

Async Request/Response

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();

Context

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.

Contribute

Check out the contribution guidelines if you want to contribute to this project.

Credits

License

MIT

About

.NET client library for Google Maps API Web Services

https://velyo.github.io/google-maps-services/

License:MIT License


Languages

Language:CSS 51.0%Language:C# 27.1%Language:JavaScript 21.3%Language:F# 0.5%Language:Batchfile 0.1%