Sha256: de0b45d8aa81ded1ca99ee7100b36c8b702ce46ec7e8f272a1812e208d439152
Contents?: true
Size: 1.37 KB
Versions: 2
Compression:
Stored size: 1.37 KB
Contents
// Get driving direction using Google Directions API. var page = require('webpage').create(), origin, dest, steps; if (phantom.args.length < 2) { console.log('Usage: direction.js origin destination'); console.log('Example: direction.js "San Diego" "Palo Alto"'); phantom.exit(1); } else { origin = phantom.args[0]; dest = phantom.args[1]; page.open(encodeURI('http://maps.googleapis.com/maps/api/directions/xml?origin=' + origin + '&destination=' + dest + '&units=imperial&mode=driving&sensor=false'), function (status) { if (status !== 'success') { console.log('Unable to access network'); } else { steps = page.content.match(/<html_instructions>(.*)<\/html_instructions>/ig); if (steps == null) { console.log('No data available for ' + origin + ' to ' + dest); } else { steps.forEach(function (ins) { ins = ins.replace(/\</ig, '<').replace(/\>/ig, '>'); ins = ins.replace(/\<div/ig, '\n<div'); ins = ins.replace(/<.*?>/g, ''); console.log(ins); }); console.log(''); console.log(page.content.match(/<copyrights>.*<\/copyrights>/ig).join('').replace(/<.*?>/g, '')); } } phantom.exit(); }); }
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
phantomjs.rb-0.0.2 | vendor/phantomjs-1.4.1_OSX/examples/direction.js |
phantomjs.rb-0.0.1 | vendor/phantomjs-1.4.1_OSX/examples/direction.js |