Zend - The PHP Company




Miscellaneous

Add Code


getMquest ~ Map Quest Link Generator  

Type: code fragment
Added by: tommyo
Entered: 08/08/2001
Last modified: 09/12/2003
Rating: - (fewer than 3 votes)
Views: 5905
This is a simple function that creates a link to a mapquest link. The function accepts the a street, city, state, zip and optionally a string for the link. If the link string is not set it uses the address for the link string.


<?php
// Function - getMquest
// Passed:
// Variables..: 4 character strings; street, city, state, 
//              zip 
// example of use..: 
//  echo getMquest('374 Center St', 'Winona', 'MN','55987');
//  echo getMquest('374 Center St', 'Winona', 'MN','55987', 'link string');
// Above would create a link to MapQuest.com that would 
//pull up a map of that location.

function getMquest($street$city$state$zip$link '')
{
    
//Store the original address
    
$Address = array( 'street' => $street
                    
'city'   => $city
                    
'state'  => $state
                    
'zip'    => $zip
                    
);
    
//Initialize local variables.
    
$Mlink "";         //Return value

    //Strip periods, commas, leading, and tailing spaces from street, city,
    
$street trim($street);
    
$street str_replace('.','',$street);
    
$street str_replace(',','',$street);
    
$street str_replace(' ','+',$street);
    
$city trim($city);
    
$city str_replace('.','',$city);
    
$city str_replace(',','',$city);
    
$city str_replace(' ','+',$city);
    
$zip trim($zip);
    
$state trim($state);

    
//Compine the given data into a url that will link to mapquest
    
$Mlink "http://www.mapquest.com/cgi-bin/ia_find?link=btwn%2Ftwn-map_results&random=565&event=find_search&SNVData=&address=" .
       
$street "&city=" $city "+&State=" $state "&Zip=" .
       
$zip "&Find+Map.x=0&Find+Map.y=0";
    switch(
true){
        case(
$link == ''):
            
$Mlink "<a href=$Mlink>" $Address['street'] . "<br>" .
                     
$Address['city'] . ", " $Address['state'] .
                     
"<br>" $Address['zip'] . "</a>";
            break;
        case(
$link != ''):
            
$Mlink "<a href=$Mlink>$link</a>";
            break;
    }
    return 
$Mlink;
}
?>
?>


Usage Example


echo "<a href=" . getMquest("374 center stret", "Winona", "MN", "55987") . ">click here to see my crib</A>";


Rate This Script





Search



This Category All Categories