Better Yahoo map links in PHP
In setting up the map links used at openmikes.org (each club's address is linked to an appropriate Yahoo Map), I wasn't happy with Yahoo's prescribed map creation methods. First, looking up the address in Yahoo and using their generate-a-link tool was obviously too manual a process. Second, the generated URLs were full of meaningless (to you and I) Yahoo-internal data. Third, and unlike the maps available via Yahoo's Yellow Pages, only address information was included in the map -- no name, no phone number. I wanted a map that, when printed, would be all that my users needed to track down the club.
On examining the Yellow Pages maps, I noted that the name and desc parameters, respectively, were used for the business name and phone number.
I also noticed that the extra data (the ed parameter, for instance) could be thrown away with no ill effect.
I used the "Interactive Map" links (not the first-generation map) as my template. These links use the following parameters:
- addr: the street address, not including city and state
- csz: city, state and zip, separated by spaces
- name: business name
- desc: business phone
and a base URL of http://maps.yahoo.com/maps_result
... except, of course, when we're dealing with a Canadian listing. Happily, the only change needed in this case is to use ca.maps.yahoo.com as the server.
So, for example, the map link for "House of Joe, 1220 West New Haven Ave., Melbourne, FL, 32904, 321-728-3200" is: http://maps.yahoo.com/maps_result?addr=1220+West+New+Haven+Ave.&csz=Melbourne+FL+32904&name=House+of+Joe&desc=321-728-3200
whereas the link for "The Supreme Bean, 16 Main St., Warkworth, ON, K0K 3K0, 705-924-1212" is: http://ca.maps.yahoo.com/maps_result?addr=16+Main+St.&csz=Warkworth+ON+K0K+3K0&name=The+Supreme+Bean&desc=705-924-1212
The PHP code used to accomplish all this follows. Note the three optional parameters -- if $country is omitted, 'us' is assumed. If $name and/or $desc are omitted, you get a map without name and/or phone information.
function maplink($street, $city, $state, $zip, $country = false, $name = false, $phone = false) { if ($country == 'ca') { $server = 'ca.maps.yahoo.com'; } else { $server = 'maps.yahoo.com'; } $link = "http://$server/maps_result?addr=" . urlencode($street) . "&csz=" . urlencode("$city $state $zip"); if ($name) { $link .= "&name=" . urlencode($name); } if ($phone) { $link .= "&desc=" . urlencode($phone); } return($link); }