All Projects โ†’ goparrot โ†’ geocoder

goparrot / geocoder

Licence: other
Geocoder is a Typescript library which helps you build geo-aware applications by providing a powerful abstraction layer for geocoding manipulations

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to geocoder

Places
๐ŸŒ Turn any <input> into an address autocomplete
Stars: โœญ 5,322 (+18907.14%)
Mutual labels:  autocomplete, geo, geolocation, places, geocoder
GoogleMapsHelper
An easy to integrate Model Based Google Maps Helper (SVHTTPClient, AFNetworking) That lets you Geo Code , Reverse Geocode, Get Directions , Places Autocomplete.
Stars: โœญ 21 (-25%)
Mutual labels:  autocomplete, google-maps, places, geocoder
Geo Golang
Go library to access geocoding and reverse geocoding APIs
Stars: โœญ 394 (+1307.14%)
Mutual labels:  arcgis, geocoding, google-maps, geocoder
svelte-mapbox
MapBox Map and Autocomplete components for Svelte (or Vanilla JS)
Stars: โœญ 267 (+853.57%)
Mutual labels:  autocomplete, geocoding, google-maps, geocode
svelte-googlemaps
Svelte Google Maps Components
Stars: โœญ 62 (+121.43%)
Mutual labels:  google-maps, geolocation, places
Googleapi
C# .NET Core Google Api (Maps, Places, Roads, Search, Translate). Supports all endpoints and requests / responses.
Stars: โœญ 346 (+1135.71%)
Mutual labels:  autocomplete, geocoding, geolocation
addressr
Free Australian Address Validation, Search and Autocomplete
Stars: โœญ 46 (+64.29%)
Mutual labels:  autocomplete, geocoding, geo
Osmunda
An offline geocode library for android, powered by SQLite, using osm data. ็ฆป็บฟๅœฐ็†็ผ–็ Androidๅบ“๏ผŒๅŸบไบŽSQLite๏ผŒไฝฟ็”จๅผ€ๆ”พ่ก—้“ๅœฐๅ›พๆ•ฐๆฎใ€‚
Stars: โœญ 37 (+32.14%)
Mutual labels:  geocoding, geocoder, geocode
python-omgeo
OMGeocoder - A python geocoding abstraction layer
Stars: โœญ 34 (+21.43%)
Mutual labels:  geocoding, geocoder, geocode
Use Places Autocomplete
๐Ÿ˜Ž ๐Ÿ“ React hook for Google Maps Places Autocomplete.
Stars: โœญ 739 (+2539.29%)
Mutual labels:  autocomplete, geocoding, google-maps
Mimirsbrunn
Geocoding and reverse-geocoding (with OSM data)
Stars: โœญ 165 (+489.29%)
Mutual labels:  autocomplete, geocoding, geocoder
Geo On Fire
A library to create high performance geolocation queries for Firebase. Checkout the demos: https://run.plnkr.co/plunks/AYaN8ABEDcMntgbJyLVW/ and https://run.plnkr.co/plunks/xJgstAvXYcp0w7MbOOjm/
Stars: โœญ 54 (+92.86%)
Mutual labels:  geocoding, geo, geolocation
React Places Autocomplete
React component for Google Maps Places Autocomplete
Stars: โœญ 1,265 (+4417.86%)
Mutual labels:  autocomplete, google-maps, geocoder
Pelias Android Sdk
Android sdk for pelias
Stars: โœญ 20 (-28.57%)
Mutual labels:  geocoding, geolocation, geocoder
Google Maps
Google Maps Web Services API wrapper for .NET
Stars: โœญ 171 (+510.71%)
Mutual labels:  geocoding, google-maps, geocoder
Django Places
A django app for store places with autocomplete
Stars: โœญ 55 (+96.43%)
Mutual labels:  autocomplete, google-maps, geolocation
local-reverse-geocoder
Local reverse geocoder for Node.js based on GeoNames data
Stars: โœญ 155 (+453.57%)
Mutual labels:  geocoding, geocoder
maps-app-dotnet
Your organization's suite of cross platform mapping apps built with the ArcGIS Runtime SDK for .NET
Stars: โœญ 20 (-28.57%)
Mutual labels:  arcgis, geocoding
google maps
๐Ÿ—บ An unofficial Google Maps Platform client library for the Rust programming language.
Stars: โœญ 40 (+42.86%)
Mutual labels:  geocoding, google-maps
geoservices-js
Deprecated - please consider using @esri/arcgis-rest-js
Stars: โœญ 53 (+89.29%)
Mutual labels:  arcgis, geocoding

Build Status Coverage Status NPM version Greenkeeper badge Commitizen friendly Conventional Commits

Geocoder

Geocoder Logo

Description

Geocoder is a Typescript library which helps you build geo-aware applications by providing a powerful abstraction layer for geocoding manipulations.

Installation

$ npm i @goparrot/geocoder reflect-metadata axios

โš ๏ธ๏ธ Each reflect-metadata installation has its own metadata storage, from which it reads and writes from. So if you had a project with multiple reflect-metadata packages, it could happen that in one file you write metadata in one reflect-metadata package and in another file youโ€™re trying to retrieve this metadata accidently from the other reflect-metadata package, which of course doesnโ€™t exist there.

Usage

Minimal

In the code snippet below we use Google provider.

import 'reflect-metadata';
import { Distance, Location, Geocoder, GoogleMapsProvider, Suggestion } from '@goparrot/geocoder';
import axios, { AxiosInstance } from 'axios';

const axios: AxiosInstance = axios.create();

const provider: GoogleMapsProvider = new GoogleMapsProvider(axios, 'YOUR_API_KEY');

const geocoder: Geocoder = new Geocoder(provider);

(async () => {
    try {
        const locations: Location[] = await geocoder.geocode({
            address: '1158 E 89th St, Chicago, IL 60619, USA',
        });

        console.info({ locations });
    } catch (err) {
        console.error(err);
    }

    try {
        const locations: Location[] = await geocoder.reverse({
            lat: 41.7340186,
            lon: -87.5960762,
        });

        console.info({ locations });
    } catch (err) {
        console.error(err);
    }

    try {
        const suggestions: Suggestion[] = await geocoder.suggest({
            address: '1158 E 89th St',
        });

        console.info({ suggestions });
    } catch (err) {
        console.error(err);
    }

    try {
        const location: Location = await geocoder.placeDetails({
            placeId: 'SOME_GOOGLE_PLACE_ID',
        });

        console.info({ location });
    } catch (err) {
        console.error(err);
    }

    try {
        const distance: Distance = await geocoder.distance({
            from: {
                lat: 40.871994,
                lon: -74.425937,
            },
            to: {
                lat: 40.863008,
                lon: -74.385286,
            },
            mode: TravelModeEnum.DRIVING,
        });

        console.info({ distance });
    } catch (err) {
        console.error(err);
    }
})();

Advanced

In the code snippet below we use Here provider.

import 'reflect-metadata';
import { Location, Geocoder, HereProvider, LoggerInterface } from '@goparrot/geocoder';
import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';

// You can use any logger that fits the LoggerInterface
const logger: LoggerInterface = console;

// Set timeout for all requests
const axios: AxiosInstance = axios.create({
    timeout: 5000,
});

// You can log all requests
axios.interceptors.request.use((request: AxiosRequestConfig) => {
    logger.debug('api request', request);

    return request;
});

// You can log all responses
axios.interceptors.response.use((response: AxiosResponse): AxiosResponse => {
    logger.debug(`api response ${response.status}`, response.data);

    return response;
});

/**
 * Caching adapter for axios. Store request results in a configurable store to prevent unneeded network requests.
 * @link {https://github.com/RasCarlito/axios-cache-adapter}
 */

const provider: HereProvider = new HereProvider(axios, 'YOUR_APP_ID', 'YOUR_APP_CODE');

const geocoder: Geocoder = new Geocoder(provider);
geocoder.setLogger(logger);

(async () => {
    try {
        const locations: Location[] = await geocoder.geocode({
            // accuracy: AccuracyEnum.HOUSE_NUMBER,
            address: '1158 E 89th St, Chicago, IL 60619, USA',
            countryCode: 'US',
            // postalCode: '60619',
            // state: 'Illinois',
            // stateCode: 'IL',
            // city: 'Chicago',
            // language: 'en', // default
            // limit: 5, // default
            // fillMissingQueryProperties: true, // default
            withRaw: true, // default false
        });

        logger.info('locations', { locations });
    } catch (err) {
        logger.error(err);
    }

    try {
        const locations: Location[] = await geocoder.reverse({
            // accuracy: AccuracyEnum.HOUSE_NUMBER,
            lat: 41.7340186,
            lon: -87.5960762,
            countryCode: 'US',
            // language: 'en', // default
            // limit: 5, // default
            // withRaw: false, // default
        });

        console.info('locations', { locations });
    } catch (err) {
        console.error(err);
    }
})();

Providers

Legend:

  • โœ… - Implemented / ready to use
  • ๐Ÿšซ - Provider doesn't support it
  • โŒ› - In progress
  • ๐Ÿ†˜ - Need help with implementation
  • ๐Ÿ”๏ธ - Need to investigate if supported by provider

Location

World

Provider Geocode Reverse Suggest Place Details Distance
Algolia Places ๐Ÿ†˜ ๐Ÿ†˜๏ธ ๐Ÿ†˜ ๐Ÿ†˜ ๐Ÿ”
ArcGIS Online โœ… โœ… โœ…๏ธ โœ… ๐Ÿ”
Bing Maps ๐Ÿ†˜ ๐Ÿ†˜๏ธ ๐Ÿ”๏ธ ๐Ÿ†˜ ๐Ÿ”
Geonames ๐Ÿ†˜ ๐Ÿ†˜๏ธ ๐Ÿ”๏ธ ๐Ÿ†˜ ๐Ÿ”
Google Maps โœ… โœ… โœ… โœ… โœ…
Here โœ… โœ… โœ… โœ… ๐Ÿ”
LocationIQ ๐Ÿ†˜ ๐Ÿ†˜๏ธ ๐Ÿ”๏ธ ๐Ÿ” ๐Ÿ”
Mapbox ๐Ÿ†˜ ๐Ÿ†˜๏ธ ๐Ÿ”๏ธ ๐Ÿ” ๐Ÿ”
MapQuest โœ… โœ… ๐Ÿšซ๏ธ ๐Ÿšซ ๐Ÿ”
Mapzen ๐Ÿ†˜ ๐Ÿ†˜๏ธ ๐Ÿ”๏ธ ๐Ÿ” ๐Ÿ”
Nominatim ๐Ÿ†˜ ๐Ÿ†˜๏ธ ๐Ÿ”๏ธ ๐Ÿ” ๐Ÿ”
OpenCage ๐Ÿ†˜ ๐Ÿ†˜๏ธ ๐Ÿ”๏ธ ๐Ÿ” ๐Ÿ”
Photon ๐Ÿ†˜ ๐Ÿ†˜๏ธ ๐Ÿ”๏ธ ๐Ÿ” ๐Ÿ”
PickPoint ๐Ÿ†˜ ๐Ÿ†˜๏ธ ๐Ÿ”๏ธ ๐Ÿ” ๐Ÿ”
TomTom ๐Ÿ†˜ ๐Ÿ†˜๏ธ ๐Ÿ”๏ธ ๐Ÿ” ๐Ÿ”
Yandex ๐Ÿ†˜ ๐Ÿ†˜๏ธ ๐Ÿ”๏ธ ๐Ÿ” ๐Ÿ†˜๏ธ

Special Geocoders and Providers

The ChainProvider

The ChainProvider is a special provider that takes a list of providers and iterates over this list to get information. Note that it stops its iteration when a provider returns a result.

import 'reflect-metadata';
import axios, { AxiosInstance } from 'axios';
import { Location, ChainProvider, HereProvider, MapQuestProvider, ProviderAggregator } from '@goparrot/geocoder';

const axios: AxiosInstance = axios.create({
    timeout: 5000,
});

const chainProvider: ChainProvider = new ChainProvider([new MapQuestProvider(axios, 'YOUR_API_KEY'), new HereProvider(axios, 'YOUR_APP_ID', 'YOUR_APP_CODE')]);

const geocoder: ProviderAggregator = new ProviderAggregator([chainProvider]);

(async () => {
    try {
        const locations: Location[] = await geocoder.geocode({
            address: '1158 E 89th St, Chicago, IL 60619, USA',
        });

        console.info({ locations });
    } catch (err) {
        console.error(err);
    }
})();

The ProviderAggregator

The ProviderAggregator is used to register several providers so that you can manualy decide which provider to use later on.

import 'reflect-metadata';
import axios, { AxiosInstance } from 'axios';
import { Location, GoogleMapsProvider, HereProvider, ProviderAggregator, MapQuestProvider } from '@goparrot/geocoder';

const axios: AxiosInstance = axios.create({
    timeout: 5000,
});

const geocoder: ProviderAggregator = new ProviderAggregator([
    new MapQuestProvider(axios, 'YOUR_API_KEY'),
    new HereProvider(axios, 'YOUR_APP_ID', 'YOUR_APP_CODE'),
]);

geocoder.registerProvider(new GoogleMapsProvider(axios, 'YOUR_API_KEY'));

(async () => {
    try {
        const locations: Location[] = await geocoder.using(GoogleMapsProvider).geocode({
            address: '1158 E 89th St, Chicago, IL 60619, USA',
        });

        console.info({ locations });
    } catch (err) {
        console.error(err);
    }
})();

The ProviderAggregator's API is fluent, meaning you can write:

const locations: Location[] = geocoder.registerProvider(new MyCustomProvider(axios)).using(MyCustomProvider).geocode({
    // ...
});

The using() method allows you to choose the provider to use by its class name. When you deal with multiple providers, you may want to choose one of them. The default behavior is to use the first one, but it can be annoying.

Versioning

Geocoder follows Semantic Versioning.

Contributing

See CONTRIBUTING file.

Unit Tests

In order to run the test suite, install the development dependencies:

$ npm i

Then, run the following command:

$ npm run coverage

Background

Inspired by geocoder-php/geocoder

License

Geocoder is MIT licensed.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].