10.4: Use Google Maps with the People widget

Jan 16, '06 06:27:00AM

Contributed by: phanofwclark

Tiger only hintAs with the Phone Book widget, I wanted to use Google maps with the new (in 10.4.4) People widget. After a little fiddling, I rewrote a bit of the code so that the widget uses Google Maps.

The code that controls the people widget is a program named WhitePages.js, located within the package for the People widget. Control-click on the People widget and select Show Package Contents from the pop-up menu; you'll find the program in the first folder that opens. Open it in your favorite text editor.

The code that plugs the info into your browser begins at line 877 by default (which reads var mapURL = "http://www.daplus.us/showmap.aspx?";). Replace all of the code down to line 902 (//pbalert("map url "+mapURL");) with this code:

var mapURL = "http://maps.google.com/maps?q="; 
	
  if (singleResult.address.length > 0)
  {
    mapURL += "";
    var tmpAddr = singleResult.address.replace(/(s*#.*$)/, "");
    mapURL += tmpAddr.replace(/\s+/g, "+");
  }
  mapURL += "+";
  mapURL += singleResult.city.replace(/\s+/g, "+");
  mapURL += "+";
  mapURL += singleResult.state.replace(/\s+/g, "+");
  if (singleResult.zip.length > 0)
  {
    mapURL += "+";
    mapURL += singleResult.zip.replace(/\s+/g, "+");
  }
  
  mapURL += "+";
  mapURL += "(";
  mapURL += singleResult.firstname.replace(/\s+/g, "+");
  mapURL += "+";
  mapURL += singleResult.lastname.replace(/\s+/g, "+");
  mapURL += ")";
Save the changes to the file, then open Dashboard, and open the People widget (close and re-open it if it was already open). You should now see Google Maps when you click someone's address.

[robg adds: As covered in an earlier hint, I recommend copying the People widget to your user's Library/Widgets folder first, then modifying the copy. This leaves the original intact, and your modified version will be used instead of the one in the system-level Library. I tested this, and it worked perfectly as described...]

Comments (16)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20060111153633868