feathers-google-maps
A Feathers service for Google Maps API
Installation
yarn add feathers-google-maps
Documentation
This service is a light wrapper around the @googlemaps/google-maps-services-js library. Please refer to the @googlemaps/google-maps-services-js documenation for options that can be passed. You will also find it helpful to reference the Google Maps Web Service APIs docs.
Available Services
The following methods are supported and map to the appropriate @google/maps methods:
- directions
- distancematrix
- elevation
- geocode
- reverseGeocode
- geolocate
- placeAutocomplete
- placeDetails
- findPlaceFromText
- placePhoto
- placesNearby
- placeQueryAutocomplete
- textSearch
- nearestRoads
- snapToRoads
- timezone
Creating a Service
const GoogleMapsService = ; const Directions = key: 'YOUR API KEY' method: 'directions'; app;
The service exposes two methods, find(params)
and create(data, params)
. These two methods are functionally equivalent. The create()
method is added so that you can take advantage of the .on('created')
service event.
When using the find(params)
method, include the query
as the params to be passed to the underlying GoogleMaps method.
app; // This will call the googlMaps method likegoogleMaps;
When using the create(data, params)
method, the data
will be passed to the underlying GoogleMaps method.
app; // This will also call the googlMaps method likegoogleMaps;
Complete Example
const feathers = ;const express = ;const socketio = ;const GoogleMapsService = ; // Initialize the applicationconst app = ; // Create a directions serviceapp; // Create a geocode serviceapp; const directionsService = app;const geocodeService = app; const successHook = { // On success, context.params.googleMaps will include a `response` console;} const errorHook = { // On error, context.params.googleMaps will include an `error` console;} directionsService; directionsService geocodeService; geocodeService directionsService ; directionsService ; geocodeService ; geocodeService ; app; console;
License
Copyright (c) 2019
Licensed under the MIT license.