Skip to content

Instantly share code, notes, and snippets.

@ba3r
Created October 8, 2009 13:19
Show Gist options
  • Save ba3r/205005 to your computer and use it in GitHub Desktop.
Save ba3r/205005 to your computer and use it in GitHub Desktop.
//version 1.56b - 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";} else {
from_prepos = "unknown"; to_prepos = "unknown";}
}}}}} }}}}}
//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"],
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: "http://synapsos.kilu.de/ubiquity/directions/wegweiser.gif",
license: "GPL",
homepage: "http://synapsos.kilu.de/ubiquity/directions/command.html",
author: { name: "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"} ],
preview: function( pblock, args )
{
if ( from_prepos == 'unknown' || to_prepos == 'unknown' )
{ var msg = 'I am sorry but your language is not yet supported by this command. Please go to <a href="http://maps.google.com">maps.google.com and try out which prepositions/phrases you have to put in the searchbar to get a route. It would be nice if you mailed these prepositions and the country you come from (' + geo + ') to synapsos@gmail.com<br>Thank you!';} else {
var msg;
var fromto = from_prepos + ' ' + args.source.text + ' ' + to_prepos + ' ' + args.goal.text;
var mapURL = 'http://maps.google.com/?key=ABQIAAAAGZ11mh1LzgQ8-8LRW3wEShQeSuJunOpTb3RsLsk00-MAdzxmXhQoiCd940lo0KlfQM5PeNYEPLW-3w&t=1';
mapURL += '&q=' + fromto ;
var height = '500px';
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 += '<br><i>GeoLocation: </i>' + geo ;
msg += '</div>';
}
pblock.innerHTML = msg ;
},
previewDelay: 333,
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 );
}
});
CmdUtils.CreateCommand({
names: ["route"],
description: "Shows a preview map with the route between 2 locations (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://synapsos.kilu.de/ubiquity/directions/command.html",
author: { name: "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"} ],
preview: function( pblock, args )
{
var msg;
var fromto = from_prepos + ' ' + args.source.text + ' ' + to_prepos + ' ' + args.goal.text;
var mapURL = 'http://maps.google.com/?key=ABQIAAAAGZ11mh1LzgQ8-8LRW3wEShQeSuJunOpTb3RsLsk00-MAdzxmXhQoiCd940lo0KlfQM5PeNYEPLW-3w&t=1&output=embed';
mapURL += '&q=' + fromto ;
var height = '500px';
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 += '<br><i>GeoLocation: </i>' + geo ;
msg += '</div>';
pblock.innerHTML = msg ;
},
previewDelay: 333,
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