Extending Piece functionality
This page explains the process of adding functionality to Pieces made with Lambda.
Current location data
While making a Piece, you may want to utilize a user’s current location data. If that’s the case, use the following procedure to request the user’s location in a simple way.
Amending PieceJSON
Add the parameters
line to the PieceJSON in the same manner as below:
"permissionList":{ "ios":["location"], "android":["location"] }, "serviceProxy":{ "service":"citizenSample", "parameters":["location"] },
Use the parameters shown in the table below to select an "accuracy" level, or the degree of detail you want to utilize user location. The more accuracy you want, the more time will be needed to obtain the location information.
Parameters | Accuracy (measurement error) |
---|---|
"location_rough" | Around ±10 km |
"location_normal" | Around ±100 m |
"location_accurate" or "location" | Highest achievable accuracy |
Acquiring current location data with ProxyCore
Once you’ve added parameters
to PieceJSON, you can obtain latitudinal and longitudinal information in ProxyCore using the method displayed below.
exports.handler = async event =>{ const latitude = event.properties.parameters.location.latitude; const longitude = event.properties.parameters.location.longitude; // Execute processing using location information }
Execution date and time
While making a Piece, you may want to use the Piece's execution date and time (i.e. the time the Piece is triggered to run) in the Piece functionality itself. If that’s the case, use the following procedure to request the execution date and time in a simple way.
Amending PieceJSON
No extra definition in PieceJSON is required. The execution date and time will be generated automatically.
Acquiring execution date and time with ProxyCore
You can obtain the Piece's execution date and time information in ProxyCore using the method described below. The data format will be yyyy-MM-dd'T'HH:mm:ssZZZ
. (e.g., 2020-08-01T09:15:30-0400)
exports.handler = async event => { const date = event.userData.date; // Code here using the execution date and time }