Better Maps

By Ben Hollis Last update Dec 22, 2005 — Installed 3,144 times.
// ==UserScript==
// @name           Better Maps
// @namespace      http://brh.numbera.com/software/greasemonkeyscripts/
// @description    Changes all Mapquest or old-style Yahoo map results to Google Maps pages.
// @include        http://www.mapquest.com/maps/map.adp*
// @include        http://maps.yahoo.com/maps_result*
// ==/UserScript==

if(window.location.search != null) {
	//This first bit builds an associative array out of the querystring variables
	var searchstring = window.location.search.substring(1, window.location.search.length);
	var namevalues = searchstring.split("&");
	var queryMap = new Array();
	for(var i=0; i < namevalues.length; i++) {
		var nvpair = namevalues[i].split("=");
		queryMap[nvpair[0]] = nvpair[1];
	}
	
	//Then we make sure the search had all the right fields and construct a google maps search line
	if(typeof(queryMap["address"]) != 'undefined' 
		&& typeof(queryMap["city"]) != 'undefined'
		&& typeof(queryMap["state"]) != 'undefined'
		&& typeof(queryMap["zipcode"]) != 'undefined'
		&& queryMap["address"] != ""
		&& queryMap["city"] != ""
		&& queryMap["state"] != ""
		&& queryMap["zipcode"] != ""
	) {
		var gaddress = escape(unescape(queryMap["address"]) + ", " + unescape(queryMap["city"]) + ", " + unescape(queryMap["state"]) + " " + unescape(queryMap["zipcode"]));
		window.location.href = "http://maps.google.com/maps?q=" + gaddress;
	}
	else if(typeof(queryMap["longitude"]) != 'undefined' && typeof(queryMap["latitude"]) != 'undefined') {
		window.location.href = "http://maps.google.com/maps?q=" + queryMap["latitude"] + "+" + queryMap["longitude"];
	}
	else if(typeof(queryMap["lat"]) != 'undefined' && typeof(queryMap["lon"]) != 'undefined') {
		window.location.href = "http://maps.google.com/maps?q=" + queryMap["lat"] + "+" + queryMap["lon"];
	}
	else if(typeof(queryMap["addr"]) != 'undefined' && typeof(queryMap["csz"]) != 'undefined') {
		window.location.href = "http://maps.google.com/maps?q=" + escape(unescape(queryMap["addr"]) + ", " + unescape(queryMap["csz"]));
	}
}