aboutsummaryrefslogtreecommitdiffstats
path: root/vnfmarket/src/main/webapp/vnfmarket/node_modules/phantomjs/lib/phantom/examples/direction.js
diff options
context:
space:
mode:
Diffstat (limited to 'vnfmarket/src/main/webapp/vnfmarket/node_modules/phantomjs/lib/phantom/examples/direction.js')
-rw-r--r--vnfmarket/src/main/webapp/vnfmarket/node_modules/phantomjs/lib/phantom/examples/direction.js35
1 files changed, 35 insertions, 0 deletions
diff --git a/vnfmarket/src/main/webapp/vnfmarket/node_modules/phantomjs/lib/phantom/examples/direction.js b/vnfmarket/src/main/webapp/vnfmarket/node_modules/phantomjs/lib/phantom/examples/direction.js
new file mode 100644
index 00000000..77044e3f
--- /dev/null
+++ b/vnfmarket/src/main/webapp/vnfmarket/node_modules/phantomjs/lib/phantom/examples/direction.js
@@ -0,0 +1,35 @@
+// Get driving direction using Google Directions API.
+
+var page = require('webpage').create(),
+ system = require('system'),
+ origin, dest, steps;
+
+if (system.args.length < 3) {
+ console.log('Usage: direction.js origin destination');
+ console.log('Example: direction.js "San Diego" "Palo Alto"');
+ phantom.exit(1);
+} else {
+ origin = system.args[1];
+ dest = system.args[2];
+ 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(/\&lt;/ig, '<').replace(/\&gt;/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();
+ });
+}