|
| 1 | +# Getting Started |
| 2 | + |
| 3 | +## Choose Packages |
| 4 | + |
| 5 | +Install the provider package that matches the service you want to call. Each provider package references the shared core abstractions. |
| 6 | + |
| 7 | +```powershell |
| 8 | +Install-Package Geocoding.Google |
| 9 | +Install-Package Geocoding.Microsoft |
| 10 | +Install-Package Geocoding.Here |
| 11 | +Install-Package Geocoding.MapQuest |
| 12 | +``` |
| 13 | + |
| 14 | +Install `Geocoding.Yahoo` only when you are maintaining a legacy compatibility flow. |
| 15 | + |
| 16 | +## Pick a Starting Provider |
| 17 | + |
| 18 | +- Start with Azure Maps when you want the actively supported Microsoft-backed provider. |
| 19 | +- Start with Google Maps when you need Google's result model or you already operate on Google Cloud. |
| 20 | +- Start with HERE or MapQuest when those services are already part of your stack. |
| 21 | +- Treat Bing Maps and Yahoo as compatibility paths, not default choices for new work. |
| 22 | + |
| 23 | +## Forward Geocoding |
| 24 | + |
| 25 | +```csharp |
| 26 | +using System.Collections.Generic; |
| 27 | +using System.Linq; |
| 28 | +using System.Threading; |
| 29 | +using Geocoding; |
| 30 | +using Geocoding.Google; |
| 31 | + |
| 32 | +CancellationToken cancellationToken = default; |
| 33 | +IGeocoder geocoder = new GoogleGeocoder("your-google-api-key"); |
| 34 | +IEnumerable<Address> addresses = await geocoder.GeocodeAsync( |
| 35 | + "1600 Pennsylvania Ave NW Washington DC 20500", |
| 36 | + cancellationToken); |
| 37 | + |
| 38 | +Address first = addresses.First(); |
| 39 | +Console.WriteLine(first.FormattedAddress); |
| 40 | +``` |
| 41 | + |
| 42 | +## Reverse Geocoding |
| 43 | + |
| 44 | +```csharp |
| 45 | +using System.Collections.Generic; |
| 46 | +using System.Threading; |
| 47 | +using Geocoding; |
| 48 | +using Geocoding.Microsoft; |
| 49 | + |
| 50 | +CancellationToken cancellationToken = default; |
| 51 | +IGeocoder geocoder = new AzureMapsGeocoder("your-azure-maps-key"); |
| 52 | +IEnumerable<Address> addresses = await geocoder.ReverseGeocodeAsync( |
| 53 | + 38.8976777, |
| 54 | + -77.036517, |
| 55 | + cancellationToken); |
| 56 | +``` |
| 57 | + |
| 58 | +## Provider-Specific Data |
| 59 | + |
| 60 | +Provider packages expose address types with service-specific fields. For example, Google results can be queried using `GoogleAddressType`: |
| 61 | + |
| 62 | +```csharp |
| 63 | +using System.Collections.Generic; |
| 64 | +using System.Linq; |
| 65 | +using System.Threading; |
| 66 | +using Geocoding.Google; |
| 67 | + |
| 68 | +CancellationToken cancellationToken = default; |
| 69 | +GoogleGeocoder geocoder = new("your-google-api-key"); |
| 70 | +IEnumerable<GoogleAddress> addresses = await geocoder.GeocodeAsync( |
| 71 | + "1600 Pennsylvania Ave NW Washington DC 20500", |
| 72 | + cancellationToken); |
| 73 | + |
| 74 | +string? country = addresses |
| 75 | + .Where(address => !address.IsPartialMatch) |
| 76 | + .Select(address => address[GoogleAddressType.Country]?.LongName) |
| 77 | + .FirstOrDefault(); |
| 78 | +``` |
| 79 | + |
| 80 | +## Signed Google Business Credentials |
| 81 | + |
| 82 | +Use signed Google business credentials only when you already rely on that legacy deployment model. |
| 83 | + |
| 84 | +```csharp |
| 85 | +using Geocoding.Google; |
| 86 | + |
| 87 | +BusinessKey businessKey = new( |
| 88 | + "your-client-id", |
| 89 | + "your-url-signing-key"); |
| 90 | + |
| 91 | +GoogleGeocoder geocoder = new(businessKey); |
| 92 | +``` |
| 93 | + |
| 94 | +## Build from Source |
| 95 | + |
| 96 | +```bash |
| 97 | +dotnet restore |
| 98 | +dotnet build Geocoding.slnx |
| 99 | +``` |
| 100 | + |
| 101 | +## Credentials |
| 102 | + |
| 103 | +- Google Maps: API key, with `BusinessKey` retained only for signed-client compatibility. |
| 104 | +- Azure Maps: subscription key. |
| 105 | +- Bing Maps: enterprise key for deprecated compatibility scenarios. |
| 106 | +- HERE: API key for the current Geocoding and Search API. |
| 107 | +- MapQuest: developer API key. |
| 108 | +- Yahoo: legacy OAuth consumer key and secret. |
| 109 | + |
| 110 | +Continue with [Provider Support](./providers) for credential setup links, provider-specific notes, and migration guidance. |
0 commit comments