Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

10.4: Use Google Maps with the People widget Apps
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...]
    •    
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[12,376 views]  

10.4: Use Google Maps with the People widget | 16 comments | Create New Account
Click here to return to the '10.4: Use Google Maps with the People widget' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.4: Use Google Maps with the People widget
Authored by: umbjm on Jan 16, '06 07:43:44AM

When I did this, every instance of the letter "s" was replaced by "+" and Google failed.

---
JM



[ Reply to This | # ]
10.4: Use Google Maps with the People widget
Authored by: umbjm on Jan 16, '06 07:45:17AM

...and the zip code was omitted from the URL.

---
JM



[ Reply to This | # ]
10.4: Use Google Maps with the People widget
Authored by: rbjorensen on Jan 16, '06 09:06:40AM

I had the same issue. Value "s" being replaced with + in the url. I'm no programming guy, but I fixed it by changing the "+" in the lines below to "s".

Replaced these lines:
mapURL += tmpAddr.replace(/s+/g, "+");
mapURL += singleResult.city.replace(/s+/g, "+");
mapURL += singleResult.state.replace(/s+/g, "+");
mapURL += singleResult.zip.replace(/s+/g, "+");
mapURL += singleResult.firstname.replace(/s+/g, "+");
mapURL += singleResult.lastname.replace(/s+/g, "+");

With these lines:
mapURL += tmpAddr.replace(/s+/g, "s");
mapURL += singleResult.city.replace(/s+/g, "s");
mapURL += singleResult.state.replace(/s+/g, "s");
mapURL += singleResult.zip.replace(/s+/g, "s");
mapURL += singleResult.firstname.replace(/s+/g, "s");
mapURL += singleResult.lastname.replace(/s+/g, "s");

I could probably just remove everything past .replace except the ;

Like I said, I'm not familiar with the .js, but I know kind of what these are doing. It's taking mapURL and adding text to the mapURL variable and replacing the string s+ with + originally. Now, I've changed it to replace s+ with s just to get it working. I know this isn't the best, because I'm sure that string is being replaced for some reason, but I don't think it was intended to replace just s with a +. He got more than he asked for with the replace.

As for the zip, the zip code get transposed into a city, state. It doesn't become part of the url.

Anyway, it's a fix until the author can tell us how to really do it. I just know it works for me right now.




[ Reply to This | # ]
10.4: Use Google Maps with the People widget
Authored by: rbjorensen on Jan 16, '06 09:23:37AM

Like I suspected, removing everything past .replace except for ; does it too:

Instead of this:
mapURL += tmpAddr.replace(/s+/g, "s");
mapURL += singleResult.city.replace(/s+/g, "s");
mapURL += singleResult.state.replace(/s+/g, "s");
mapURL += singleResult.zip.replace(/s+/g, "s");
mapURL += singleResult.firstname.replace(/s+/g, "s");
mapURL += singleResult.lastname.replace(/s+/g, "s");

You can use this:
mapURL += tmpAddr;
mapURL += singleResult.city;
mapURL += singleResult.state;
mapURL += singleResult.zip.replace;
mapURL += singleResult.firstname;
mapURL += singleResult.lastname;

But, like I said, there must be some reason he had the s+ string replacement in there. He just didn't mean to replace all "s". Let us know.

Thx.



[ Reply to This | # ]
10.4: Use Google Maps with the People widget
Authored by: phanofwclark on Jan 16, '06 09:43:30AM

What happened was all of the backslashes got cut out for some reason inside the code.

Each of the /s+/g should read as /\s+/g

What it's doing is replacing all of the " " with a "+" for the URL (so we don't have "%20" or some nonsense going into the query string for the spaces). the /\s finds a single character of white space, and the +/g part of it makes it search throughout the whole string.



[ Reply to This | # ]
10.4: Use Google Maps with the People widget
Authored by: phanofwclark on Jan 16, '06 09:47:26AM
It is working in the preview, but gets cut out when posted. there is a backslash (the one about the enter key and to the right of the backet key) after each of the /s.

[ Reply to This | # ]
10.4: Use Google Maps with the People widget
Authored by: robg on Jan 17, '06 11:18:24AM
Please read the big, bold, red warning directly above the comment input box:

To protect special characters such as \, <, and >, please use the [code] and [\code] tags around any XML, UNIX code, AppleScripts, or other code fragments in your submission! Yes, those are square brackets, and remember to set the post mode to 'HTML formatted,' too.

If you don't use square brackets, you lose the special characters.

-rob.

[ Reply to This | # ]
10.4: Use Google Maps with the People widget
Authored by: robg on Jan 17, '06 11:27:20AM

BTW, I also edited the original hint, so this conversation remains for historical reasons only :).

-rob.



[ Reply to This | # ]
10.4: Use Google Maps with the People widget
Authored by: phanofwclark on Jan 16, '06 09:52:09AM

In the interest of making this a little bit more visible...

It is working in the preview, but gets cut out when posted. there is a backslash (the one about the enter key and to the right of the backet key) after each of the /s .



[ Reply to This | # ]
10.4: Use Google Maps with the People widget
Authored by: umbjm on Jan 16, '06 12:45:04PM

That fixed it for me--thanks.

---
JM



[ Reply to This | # ]
10.4: Use Google Maps with the People widget
Authored by: Brock Lee on Jan 16, '06 04:35:07PM

Well that instruction looks misleading, as it could be read that the backslash is placed after the "s". Basically there should be a backslash between every slash and "s".



[ Reply to This | # ]
10.4: Use Google Maps with the People widget
Authored by: PeterVana on Jan 16, '06 01:42:23PM

Thanks for the help.
I am experiencing a similar issue where each "s", except the first letter in a word, is being preplaced with a blank space. Unfortunately, I am a total not-geek. Can you suggest a correction that I could implement?



[ Reply to This | # ]
10.4: Use Google Maps with the People widget
Authored by: capacity on Jan 16, '06 04:40:29PM
To make clicking on the person's address search for that person in Google's Residential Phonebook rather than just going to a map of the address associated with that person as the originally posted code does, use this chunk of code:

// Search Google's Residential Phonebook
var mapURL = "http://www.google.com/search?sa=X&oi=fwp&pb=f&q=";
mapURL += singleResult.firstname.replace(/\s+/g, "+");
mapURL += "+";
mapURL += singleResult.lastname.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, "+");
    }
Note: After every
 .replace( 
there is a forward slash, back slash, s, plus sign, forward slash, g, comma, double quote, plus sign, double quote, end parentheses, and semicolon.

Clicking the person's name will go to their daplus.us entry. I don't know Java Script very well, but I would assume that if someone wanted to they could have the widget search and return data from Google's Residential Phonebook, have clicking on the name show Google's Residential Phonebook result, and have clicking on the address plot a map.

[ Reply to This | # ]
10.4: Use Google Maps with the People widget
Authored by: phanofwclark on Jan 16, '06 06:06:26PM

The code above is what I had typed out, but the slashes kept getting erased once I submitted the code. I suppose it is a PHP issue.



[ Reply to This | # ]
10.4: Use Google Maps with the People widget
Authored by: capacity on Jan 17, '06 05:12:31AM

Seems as though for the back slashes to stick around you need to use the code tags with the square brackets, not the pointy ones.



[ Reply to This | # ]
10.4: Use Google Maps with the People widget
Authored by: paulclaude on Jan 17, '06 01:24:19AM
Is there anybody that knew a method to extract the JS code from Phone Book Widget or Easy Envelope Widget and create a little JS script that read addresses from the addressbook.data database (I don't know how JavaScripting...)?

---
PaulClaude

[ Reply to This | # ]