IDL.MapsApi.Net
1.0.1
dotnet add package IDL.MapsApi.Net --version 1.0.1
NuGet\Install-Package IDL.MapsApi.Net -Version 1.0.1
<PackageReference Include="IDL.MapsApi.Net" Version="1.0.1" />
paket add IDL.MapsApi.Net --version 1.0.1
#r "nuget: IDL.MapsApi.Net, 1.0.1"
// Install IDL.MapsApi.Net as a Cake Addin
#addin nuget:?package=IDL.MapsApi.Net&version=1.0.1
// Install IDL.MapsApi.Net as a Cake Tool
#tool nuget:?package=IDL.MapsApi.Net&version=1.0.1
IDL.MapsApi.Net
This is a .Net library for accessing the Google Maps and MapBox geolocation APIs. At the moment there is only support for the forward lookup where you get a lat/long from a location string, reverse where you get an address from a lat/long and Google directions. The library is based on simple requests to the MapsApi client for the service that you requre:
IApiClient googleClient = new new ApiClient();
var request = new GoogleForwardGeocodingRequest(new GoogleCredentials(key))
{
Query = "BS13RW"
};
var googleResponse = googleClient.GetAsync(request);
IApiClient mapBoxClient = new new ApiClient();
var request = new MapBoxForwardGeocodingRequest(key)
{
Query = "BS13RW"
};
var mapBoxResponse = mapBoxClient.GetAsync(request);
Each request has a sepcific response that represents the data that the provider supplies, Google Maps and MapBox both return different data for the same type of request. MapsApi contains extension methods that convert these into a common format with a basic generic fields for what is required.
var response = client.GetAsync(request).Result.AsMapsApiGeocodingResult();
This returns a collection of Result objects.
public class Result
{
public Address Address { get; internal set; }
public BoundingBox Boundry { get; internal set; }
public string Id { get; internal set; }
public Location Location { get; internal set; }
}
By default the path and API keys are picked up from the AppSettings configuration section with the following keys:
- MapBoxApiKey
- MapBoxGeoApiEndPoint
- GoogleMapsApiKey
- GoogleMapsGeoApiEndPoint
This can be overridden by passing the root path to the ApiClient constructor or setting the RootPath of a request and passing in the api key or in the case of the Google requests a GoogleCredentials class to the request constructor. This is because from expreience the path formats can be different when using different requests to the same provider.
If you would rather use a different client than the built in one you can create a wrapper for libraries such as RestSharp.
public class RestSharpClientWrapper : ApiClient
{
private readonly IRestClient _client;
public RestSharpClientWrapper(IRestClient client = null)
{
_client = client ?? new RestClient();
_client.ClearHandlers();
_client.AddHandler("application/vnd.geo+json", new JsonDeserializer());
}
public override Task<TResponse> GetAsync<TResponse>(IRequest<TResponse> request)
{
_client.BaseUrl = new Uri(request.RootPath);
var response = _client.GetTaskAsync<TResponse>(new RestRequest(request.Path) { RequestFormat = DataFormat.Json });
return response;
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET Framework | net45 is compatible. net451 was computed. net452 was computed. net46 was computed. net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
This package has no dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|
Added in the ability to set a client id and signature for Google API requests