Sha256: 1f000ec936e5c6e17ad6ff8a435006f30f1e182e83c645b7594ecf2e44c596d3
Contents?: true
Size: 1.29 KB
Versions: 2
Compression:
Stored size: 1.29 KB
Contents
# Get driving direction using Google Directions API. page = require('webpage').create() system = require 'system' if system.args.length < 3 console.log 'Usage: direction.coffee origin destination' console.log 'Example: direction.coffee "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'), (status) -> if status isnt 'success' console.log 'Unable to access network' else steps = page.content.match(/<html_instructions>(.*)<\/html_instructions>/ig) if not steps console.log 'No data available for ' + origin + ' to ' + dest else for ins in steps 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.5.0-liunx-x86-dynamic/examples/direction.coffee |
phantomjs.rb-0.0.1 | vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/direction.coffee |