Distance Compare Class Part B
This post assumes advanced understanding of PHP and some object orientated knowledge.
In my last post, I outlined a basic class that compares addresses by distance. The class returns a sorted, filtered, or single best match from an array of addresses based on a single comparison address. However, this didn't fulfill my client's needs completely. I needed to extend this class to fill his needs, so I made a new class that utilized my basic class.
The first step was making a construct method that extended to gDistanceCompare's construct method. To do this, all I needed to do is put parent:: in front of the class method from gDistanceCompare.
public function __construct()
{
parent::__construct($this->_readCSV('PL_Locator_Website_Confirmations.csv'));
}
The client's information was in a csv file, so I made a method for turning the CSV information into an array that gDistanceCompare needs.
private function _readCSV($url)
{
$handle = fopen($url,'r');
while(($data = fgetcsv($handle,1000,","))!=false)
if($data[1]!='Street Address') $array[] = $data[1].', '.$data[2].', '.$data[3].' '.$data[4];
fclose($handle);
return $array;
}
To read the CSV, you need to loop through the file with...
read more »