MapWrap 📌
Changelog - updated for 2.1.0
About
MapWrap is a simple wrapper around the Google Maps API for Geocoding, Directions, and Places (Nearby Search, Place Details). It provides simple methods to access data members in the API response with error checking.
MapWrap also implements a simple LRU cache to speed up requests and decrease the amount of unnecessary calls to the server. It is fully compliant with Google's restriction of not caching data for over 30 days.
Installation
npm install --save mapwrap
Usage
const MapWrap = ; const mapwrap = ; async { try const geoWrapper = await mapwrap; console; // return an array of objects console; // return first address in its object console; // return first address as a string const reverseGeoWrapper = await mapwrap; console; console; console; /* Allowed modes: https://developers.google.com/maps/documentation/directions/intro#TravelModes */ const directionsParams = origin: "Anaheim" // required destination: "Irvine" // required mode: "driving" altRoutes: true // false by default. retrieve alternate routes (up to 3, usually) avoidFerries: false avoidHighways: false avoidIndoor: false avoidTolls: false units: "imperial" // or "metric" ; const directionsWrapper = await mapwrap; /* The methods getStartAddress, getEndAddress, getRoute, and getRouteSteps accepts an optional number to specify which route you want to retrieve data from. Useful only when altRoutes is set to true in directionsParams. Defaults to 0 if not specified. */ console; console; console; console; console; const placeSearchWrapper = await mapwrap; console; /* What is next page token? https://developers.google.com/places/web-service/search#PlaceSearchPaging */ console; /* commented out as Google Maps API requires a small amount of time before the next page token becomes valid. https://stackoverflow.com/questions/21265756/paging-on-google-places-api-returns-status-invalid-request const placeSearchWrapper2 = await mapwrap.additionalPlaces(placeSearchWrapper.getNextPageToken()); */ const placeDetailsObject = await mapwrap; console; catch err console; };
If any bugs are found, please don't hesitate to open an issue on the project repo. I'll do my best to address them.