1.13.0 • Published 5 years ago

gmp-io19-demo v1.13.0

Weekly downloads
-
License
MIT
Repository
-
Last release
5 years ago

Google Maps Platform Module

This module orchestrates API requests to Google Maps Platform.

Setup

To use, do the following:

  1. Generate an API key from a GCP account with the Places API enabled.
  2. Run npm install.
  3. Require and instantiate the module, pasting your API Key:

    const GMP = require('./gmpclient');
    const client = new GMP('YOUR_API_KEY');
  4. Pre-populate the high RPS cache:

    Since it takes a few API calls to pre-populate the cache, you should call client.populateCache() right after the client is instantiated so there's no waiting later on:

    await client.populateCache();
  5. Call the API:

    let initialOriginsCollection = getOrigins(false);
    let initialOrigins = initialOriginsCollection.features;
    for (let i = 0; i < initialOrigins.length; i++) {
      let originID = initialOrigins[i].properties.place_id;
      let originDetails = getPlaceDetails(originId;)
      if (originDetails.photos) {
        let firstPhotoRef = originDetails.photos[0].photo_reference;
      }
    
      let originCoord = initialOrigins[i].geometry.coordinates;
      let destinationCoord = [37.4268384,-122.082891];
      let originRoutes = getDirections(originCoord, destinationCoord);
    }

Function Details

  • getPlaceDetails : Fetches the full details about a place.
    • Parameter: placeId {String} (Required) A Google Maps Place ID
    • Return: {JSON} Object in the format described in Places Details Responses
  • getPlacesPhoto : Serves a photo's binary file
    • Parameters :
      • photoref {String} (Required) A string identifier that uniquely identifies a photo. Photo references are returned from a Place Details request.
      • maxwidth or maxheight {Integer} (At least one of these required) Specifies the maximum desired height or width, in pixels, of the image returned by the Place Photos service. If the image is smaller than the values specified, the original image will be returned. If the image is larger in either dimension, it will be scaled to match the smaller of the two dimensions, restricted to its original aspect ratio. Both the maxheight and maxwidth properties accept an integer between 1 and 1600.
    • Return : {Image file} The response of a successful Place Photo request will be an image. The type of the image will depend upon the type of the originally submitted photo. More details at Place Photo Response
  • getDirections : Generates driving directions between two points
    • Parameters :
      • origin {Array} (Required) A list of a latitude and longitude in decimal format
      • destination {Array} (Required) A list of latitude and longitude in decimal format
      • mode {String} (Required) The mode of transit. 'driving', 'walking', 'bicycling', 'transit' are supported.
    • Return : {JSON} Object in the format described in Directions Sample Responses
  • getOrigins : Provides 10 origins in the SF bay area at a time
    • Parameters :
      • scaled {Boolean} (Required) Indicates whether we want origins in interactive mode (10 pre-set origins for displaying directions) or in scaled mode (10 random origins from around the bay area for simulating a large number of simultaneous requests)
    • Return : {GeoJSON} A GeoJSON FeatureCollection object in the format described in Load GeoJSON though the feature types are Points instead of Polygons. An example featuring a FeatureCollection of Points is used in the Visualizing Data Tutorial.
  • populateCache : Pre-populates the highRPS cache. You should call this on startup.
1.13.0

5 years ago

1.12.0

5 years ago

1.11.0

5 years ago

1.10.0

5 years ago

1.9.0

5 years ago

1.8.0

5 years ago

1.7.0

5 years ago

1.6.0

5 years ago

1.5.0

5 years ago

1.4.0

5 years ago

1.3.0

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.0

5 years ago