This library contains various some simple .NET wrapper code over some google webservices.
Currently, it's wrapping code over some maps/places webservices.
NOTE: This simple library is not intended to replace official Google .NET SDK's. It's only to simplfiy calling some of their simple endpoints.
GeocodeAsync
: convert an address into a Latitude/Longitude.AutocompleteAsync
: convert a query into a list of possible addresses.DetailsAsync
: convert a Google PlaceId into a nicely Address object.CleanUpAddressAsync
: convert an address's abbreviations all into long format. e.g. St. (for street) -> Street. NOTE: This callsAutocomplete
and thenDetails
.
Test out some of the endpoints on a live website.
Given an query/address, this get's the Latitude and Longitude of the location.
// Arrange.
var service = new GoogleMapsApiService(yourGoogleMapsApiKey, null || mockHttpClient);
// Act.
var result = await service.GeocodeAsync("Bondi Beach, Sydney, Australia");
// Now you can access:
// result.Address
// result.Coordinate.Latitude
// result.Coordinate.Longitude
Remarks: Learn what geocoding is on Wikipedia.
Given a query lets see what possible address locations might be available.
NOTE: PlaceId
is a specific, unique Google Id to identify the result location.
// Arrange.
var service = new GooglePlacesApiService(yourGoogleMapsApiKey, null || mockHttpClient);
// Act.
var result = await service.AutocompleteAsync("Bondi Beach, Sydney, Australia");
// Now you can access:
// result.Address.PlaceId
// result.Address.Location
Given a (Google) PlaceId, return the Address components for that location.
// Arrange.
var service = new GooglePlacesApiService(yourGoogleMapsApiKey, null || mockHttpClient);
// Act.
var result = await service.DetailsAsync("1234ABCD...");
// Now you can access:
// result.Address.StreetNumber
// result.Address.Street.LongName (e.g. Smith Street)
// result.Address.Street.ShortName (e.g. Smith St)
// result.Address.Suburb.LongName (e.g. Hawthorn)
// result.Address.Suburb.ShortName (e.g. Hawthorn -- yeah, basically the same as LongName, 99% of the time...)
// result.Address.City
// result.Address.State.LongName (e.g. New South Wales)
// result.Address.State.ShortName (e.g. NSW)
// result.Address.Country.LongName (e.g. Australia)
// result.Address.Country.ShortName (e.g. AU)
// result.Address.Postcode
Given an exact address (because we don't know the PlaceId
) get the details for the (expected) found location.
Note: This first calls AutocompleteAsync
and if we have 1 result exactly, then calls DetailsASync
and extracts the address components.
// Arrange.
var service = new GooglePlacesApiService(yourGoogleMapsApiKey, null || mockHttpClient);
// Act.
var result = await service.CleanUpAsync("1 Bondi Beach, Sydney, Australia");
// Now you can access:
// result.Address.StreetNumber
// result.Address.Street.LongName (e.g. Smith Street)
// result.Address.Street.ShortName (e.g. Smith St)
// result.Address.Suburb.LongName (e.g. Hawthorn)
// result.Address.Suburb.ShortName (e.g. Hawthorn -- yeah, basically the same as LongName, 99% of the time...)
// result.Address.City
// result.Address.State.LongName (e.g. New South Wales)
// result.Address.State.ShortName (e.g. NSW)
// result.Address.Country.LongName (e.g. Australia)
// result.Address.Country.ShortName (e.g. AU)
// result.Address.Postcode
License: this code is licensed under MIT. -- end of file --