Created
August 20, 2009 10:52
-
-
Save ba3r/170980 to your computer and use it in GitHub Desktop.
ubiquity google maps directions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//version 1.41b - Search for a route with Google Maps (supports many languages) | |
var from_prepos; | |
var to_prepos; | |
var geo = CmdUtils.getGeoLocation().country; | |
//German | |
if ( geo == 'Germany' || geo == 'Austria' || geo == 'Switzerland' ) | |
{from_prepos = "von"; to_prepos = "nach";} else { | |
//Japanese | |
if ( geo == 'Japan' ) | |
{from_prepos = ""; to_prepos = "から";} else { | |
//English | |
if ( geo == 'United States of America' || geo == 'United States' || geo == 'US' || geo == 'United Kingdom' || geo == 'Great Britain' || geo == 'UK' || geo == 'Ireland' || geo == 'Canada' || geo == 'India' || geo == 'Malta' || geo == 'New Zealand' || geo == 'Pakistan' || geo == 'Philippines' || geo == 'Singapore' || geo == 'South Africa' || geo == 'The Bahamas' || geo == 'Nigeria' || geo == 'Jamaica' || geo == 'Tanzania' || geo == 'Sudan' || geo == 'Kenya' || geo == 'Madagascar' || geo == 'Fiji' ) | |
{from_prepos = "from"; to_prepos = "to";} else { | |
//Italian | |
if ( geo == 'Italia' ) | |
{from_prepos = "da"; to_prepos = "a";} else { | |
//Dutch | |
if ( geo == 'Netherlands' || geo == 'The Netherlands' || geo == 'Kingdom of the Netherlands' ) | |
{from_prepos = "van"; to_prepos = "naar";} else { | |
//Czech, Polish | |
if ( geo == 'Czech Republic' || geo == 'Poland' ) | |
{from_prepos = "z"; to_prepos = "do";} else { | |
//Russian | |
if ( geo == 'Russia' || geo == 'Russian Federation' ) | |
{from_prepos = "из"; to_prepos = "в";} else { | |
//Portuguese (Brazil) | |
if ( geo == 'Brazil' || geo == 'Brazilian Republic' ) | |
{from_prepos = "de"; to_prepos = "para";} else { | |
//Danish, Icelandish | |
if ( geo == 'Denmark' || geo == 'Danmark' || geo == 'Greenland' || geo == 'Faroe Islands' || geo == 'Iceland') | |
{from_prepos = "fra"; to_prepos = "til";} else { | |
//Spanish, French | |
if ( geo == 'Spain' || geo == 'Espana' || geo == 'France' || geo == 'Belgium' || geo == 'Luxembourg' || geo == 'Monaco' || geo == 'Benin' || geo == 'Burkina Faso' || geo == 'Burundi' || geo == 'Chad' || geo == 'Democratic Republic of the Congo' || geo == 'Republic of the Congo' || geo == 'Congo' || geo == 'Gabon' || geo == 'Guinea' || geo == 'Mali' || geo == 'Senegal' || geo == 'Togo' || geo == 'Niger' || geo == 'Haiti' || geo == 'Andorra' || geo == 'Argentina' || geo == 'Bolivia' || geo == 'Chile' || geo == 'Colombia' || geo == 'Costa Rica' || geo == 'Cuba' || geo == 'Dominican Republic' || geo == 'Ecuador' || geo == 'El Salvador' || geo == 'Equatorial Guinea' || geo == 'Guatemala' || geo == 'Honduras' || geo == 'Mexico' || geo == 'Nicaragua' || geo == 'Panama' || geo == 'Paraguay' || geo == 'Peru' || geo == 'Puerto Rico' || geo == 'Uruguay' || geo == 'Venezuela' ) | |
{from_prepos = "de"; to_prepos = "a";} | |
}}}}} }}}} | |
//TODO: Add more countries and try which prepositions work in Google Maps Search. | |
//Please tell me the prepositions after you tried them out or build your own script! | |
CmdUtils.CreateCommand({ | |
names: ["directions", "route"], | |
description: "Shows a map with driving directions from one location to another (0.5+)", | |
help: "Connect 2 places/addresses with the to-preposition in your ubiquity parser language, e.g. route madrid av de america hasta barcelona passeig de miramar - for the Spanish parser", | |
icon: "chrome://ubiquity/skin/icons/map.png", | |
license: "GPL", | |
homepage: "http://icecreamfactory.freehostia.com/ubiquity/directions.php", | |
author: { name: "Mike Chow, modified by Michael Baer", homepage: "http://twitter.com/synapsos"}, | |
arguments: [{role: 'source', nountype: noun_type_async_address, label: "location 1"}, | |
{role: 'goal', nountype: noun_arb_text, label: "location 2"} ], | |
_getMapUrl: function() { | |
var loc = CmdUtils.getGeoLocation(); | |
var mapUrl = "http://maps.google.com/staticmap?"; | |
var params = { | |
center: loc.lat + "," + loc.long, | |
size: "200x250", | |
zoom: 3, | |
key: "ABQIAAAAGZ11mh1LzgQ8-8LRW3wEShQeSuJunOpTb3RsLsk00-MAdzxmXhQoiCd940lo0KlfQM5PeNYEPLW-3w" | |
}; | |
return mapUrl + jQuery.param( params ); | |
}, | |
preview: function( pblock, args ) | |
{ | |
var msg; | |
var fromto = from_prepos + ' ' + args.source.text + ' ' + to_prepos + ' ' + args.goal.text; | |
var mapURL = this._getMapUrl(); | |
mapURL += encodeURIComponent(fromto) ; | |
var height = '400px'; | |
var width = '100%'; | |
msg = '<iframe src="' + mapURL + '" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" align="right" hspace="0" vspace="0" height="' + height + '" width="' + width + '"></iframe>'; | |
msg += '<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>'; | |
msg += '<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>'; | |
msg += '<div align="left>'; | |
msg += '<i>Zoom: </i>Double Click with mouse'; | |
msg += '<br><i>GeoLocation: </i>' + geo ; | |
msg += '<br><i>mapURL: </i>' + mapURL; | |
msg += '<br><i>themap: </i>' ; | |
msg += '</div>'; | |
pblock.innerHTML = msg ; | |
}, | |
execute: function( args ) | |
{ | |
var url = "http://maps.google.com/?q="; | |
var fromto = from_prepos + ' ' + args.source.text + ' ' + to_prepos + ' ' + args.goal.text; | |
url += fromto ; | |
Utils.openUrlInBrowser( url ); | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment