source: other-projects/FileTransfer-WebSocketPair/Themes/themebuilder/bin/phantomjs-1.9.2-windows/examples/direction.js@ 31525

Last change on this file since 31525 was 31525, checked in by ak19, 7 years ago

Nathan provided more stuff: Themes folder contains Sencha's Themebuilder which generates GXT Themes. It includes the .theme and generated .jar files for the project theme.

File size: 1.4 KB
Line 
1// Get driving direction using Google Directions API.
2
3var page = require('webpage').create(),
4 system = require('system'),
5 origin, dest, steps;
6
7if (system.args.length < 3) {
8 console.log('Usage: direction.js origin destination');
9 console.log('Example: direction.js "San Diego" "Palo Alto"');
10 phantom.exit(1);
11} else {
12 origin = system.args[1];
13 dest = system.args[2];
14 page.open(encodeURI('http://maps.googleapis.com/maps/api/directions/xml?origin=' + origin +
15 '&destination=' + dest + '&units=imperial&mode=driving&sensor=false'), function (status) {
16 if (status !== 'success') {
17 console.log('Unable to access network');
18 } else {
19 steps = page.content.match(/<html_instructions>(.*)<\/html_instructions>/ig);
20 if (steps == null) {
21 console.log('No data available for ' + origin + ' to ' + dest);
22 } else {
23 steps.forEach(function (ins) {
24 ins = ins.replace(/\&lt;/ig, '<').replace(/\&gt;/ig, '>');
25 ins = ins.replace(/\<div/ig, '\n<div');
26 ins = ins.replace(/<.*?>/g, '');
27 console.log(ins);
28 });
29 console.log('');
30 console.log(page.content.match(/<copyrights>.*<\/copyrights>/ig).join('').replace(/<.*?>/g, ''));
31 }
32 }
33 phantom.exit();
34 });
35}
Note: See TracBrowser for help on using the repository browser.