@Leetcat wrote:
I want to use the node package "gtfs-realtime-bindings" in my ionic project.
You can find it here: https://www.npmjs.com/package/gtfs-realtime-bindingsBut once I do
npm install gtfs-realtime-bindings
then I add the example code into one of my controllers:angular.module('app.controllers', []) .controller('MapCtrl', function($scope, $state) { var GtfsRealtimeBindings = require('gtfs-realtime-bindings'); var request = require('request'); var requestSettings = { method: 'GET', url: 'URL OF YOUR GTFS-REALTIME SOURCE GOES HERE', encoding: null }; request(requestSettings, function (error, response, body) { if (!error && response.statusCode == 200) { var feed = GtfsRealtimeBindings.FeedMessage.decode(body); feed.entity.forEach(function(entity) { if (entity.trip_update) { console.log(entity.trip_update); } }); } }); });
I get the error..
Error: Can't find variable: require
.What other js code needs to be added?
Posts: 6
Participants: 2