• Stars
    star
    443
  • Rank 97,970 (Top 2 %)
  • Language
    C#
  • License
    MIT License
  • Created about 12 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

C# GeoCoding / Address Validation API

Generic C# Geocoding API Build Status

Includes a model and interface for communicating with five popular Geocoding providers. Current implementations include:

The API returns latitude/longitude coordinates and normalized address information. This can be used to perform address validation, real time mapping of user-entered addresses, distance calculations, and much more.

See latest release notes.

⚠️ There is a potential issue (#29) regarding MapQuest that has a workaround. If you would like to help fix the issue, PRs are welcome.

Installation

Install via nuget:

Install-Package Geocoding.Core

and then choose which provider you want to install (or install all of them):

Install-Package Geocoding.Google
Install-Package Geocoding.MapQuest
Install-Package Geocoding.Microsoft
Install-Package Geocoding.Yahoo
Install-Package Geocoding.Here

Example Usage

Simple Example

IGeocoder geocoder = new GoogleGeocoder() { ApiKey = "this-is-my-google-api-key" };
IEnumerable<Address> addresses = await geocoder.GeocodeAsync("1600 pennsylvania ave washington dc");
Console.WriteLine("Formatted: " + addresses.First().FormattedAddress); //Formatted: 1600 Pennsylvania Ave SE, Washington, DC 20003, USA
Console.WriteLine("Coordinates: " + addresses.First().Coordinates.Latitude + ", " + addresses.First().Coordinates.Longitude); //Coordinates: 38.8791981, -76.9818437

It can also be used to return address information from latitude/longitude coordinates (aka reverse geocoding):

IGeocoder geocoder = new YahooGeocoder("consumer-key", "consumer-secret");
IEnumerable<Address> addresses = await geocoder.ReverseGeocodeAsync(38.8976777, -77.036517);

Using Provider-Specific Data

GoogleGeocoder geocoder = new GoogleGeocoder();
IEnumerable<GoogleAddress> addresses = await geocoder.GeocodeAsync("1600 pennsylvania ave washington dc");

var country = addresses.Where(a => !a.IsPartialMatch).Select(a => a[GoogleAddressType.Country]).First();
Console.WriteLine("Country: " + country.LongName + ", " + country.ShortName); //Country: United States, US

The Microsoft and Yahoo implementations each provide their own address class as well, BingAddress and YahooAddress.

API Keys

Google requires a new Server API Key to access its service.

Bing requires an API key to access its service.

You will need a consumer secret and consumer key (PDF) for Yahoo.

MapQuest API requires a key. Sign up here: (http://developer.mapquest.com/web/products/open)

HERE requires an app ID and app Code

How to Build from Source

dotnet restore
dotnet build

For a nice experience, use Visual Studio Code to work with the project. The editor is cross platform and open source.

Alternatively, if you are on Windows, you can open the solution in Visual Studio and build.

Service Tests

You will need to generate API keys for each respective service to run the service tests. Make a settings-override.json as a copy of settings.json in the test project and put in your API keys. Then you should be able to run the tests.

More Repositories

1

react-bs-notifier

A react component to show growl-like notifications using bootstrap alerts
JavaScript
111
star
2

lottie-to-svg

Convert a lottie animation to an SVG file
JavaScript
93
star
3

requirejs-web-workers

Loader plugin to use web workers with require.js
JavaScript
47
star
4

ghost

Ghost on Azure App Service
JavaScript
28
star
5

chadly.net

Personal website built with Gatsby
MDX
16
star
6

xunit-bdd

Small BDD Framework built on top of xUnit
C#
13
star
7

gatsby-plugin-env-variables

Gatsby plugin to allow system environment variables to be made available to client-side scripts
JavaScript
11
star
8

gui.keepass.io

A web GUI for your Keepass database
JavaScript
10
star
9

flowise

A template to create an LLM app using Flowise
Shell
8
star
10

rtsp

RTSP Camera Streaming to Chromecast
C#
5
star
11

gatsby-remark-lottie

Gatsby remark plugin to embed lottie JSON animations with SVG placeholders
JavaScript
5
star
12

react-socket-hooks

A set of react hooks to work real nice with the WebSocket API
JavaScript
4
star
13

smartthings

My collection of SmartThings apps and device handlers
Groovy
4
star
14

eslint-plugin-inflection

ESLint plugin to check inflection of filenames
JavaScript
3
star
15

metalsmith-flatten

A metalsmith plugin to flatten a directory hierarchy
JavaScript
3
star
16

markdown-folder-transformer

Migrates my obsidian vault to Logseq format
TypeScript
2
star
17

cams

Post-process recorded surveillance camera footage from Foscam & Amcrest cameras
C#
2
star
18

signal-gpt

Connect GPT-4 to your Signal phone number
TypeScript
2
star
19

clean-blog

Ghost 2.0 Theme
HTML
1
star
20

gatsby-plugin-hello-dev

Gatsby plugin to add an HTML comment to the top of your pages greeting developers who view source of your site
JavaScript
1
star
21

obsidian-logseq-gpt-migrator

Migrate my Obsidian vault to Logseq using GPT-4
TypeScript
1
star
22

clone-github-org

A .net CLI utility to clone all repositories in a Github org
C#
1
star
23

prod-env-variables

Use one set of environment variables on development branches and another set on the default branch.
JavaScript
1
star
24

trogdor

After Effects web animation of Trogdor
1
star