Welcome, Guest | Sign In

Submit - Cancel

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 »

Distance Compare Class Part A

This post assumes advanced understanding of PHP scripting and some object-orientated knowledge.

One area of PHP that I haven't had much experience with yet is classes. I have a rough idea of what they do, but after working with a few inefficient classes, figured that they are more trouble then they're worth. It wasn't until one of my contract jobs specifically requested an application built up from a class that I actually built one from scratch and started understanding the true benefit of object-orientated programming.

In this scenario, the client owned about eight stores with unique addresses. They wanted a page on their website that allowed a user to input a zip code in a form to find the closest stores. There are several php classes online that can do this, but they depend on custom databases with zip code information built in and only calculate straight-line distances. As zip codes change over time, these classes became outdated quickly, requiring regular maintenance.

For this project, I decided to connect to Google Maps to find out the driving distance between the user's zip code and the available stores. The first step, though, is creating the class with a construct method. I wanted this class to work regardless of the method of address retrieval...

read more »

Tick Mountain Hike

Called Tick Mountain by Geocachers, there was a rocky peak on the outskirts of the Huron Mountains that had steadily become a thorn in my side. I first tried to climb the peak with a friend during the winter and was forced to turn around within site of the final climb because of time constraints. My second attempt ended abruptly when both I and my hiking partner fell through the ice of Little Huron River in the early spring. This was my third attempt, in the midst of summer, and I was determined to make the climb.

One of the peaks near Tick Mountain

One of the peaks near Tick Mountain

Tick Mountain rises from the banks of Little Huron River like a long spine of rocky peaks. There are four separate rocky outcroppings, with the eastern one being the tallest at 1342'. This point is separated from the rest of the spine by a 300' dip, which is the challenge I turned away from during my first climb. The first two outcroppings have limited western views of Bald Mountain and an unnamed peak nearby, but the second two have expansive views in all directions. This makes the mountain an ideal...

read more »

Yellow Dog River

The Yellow Dog River has recently gained media attention as one of the two waterways endangered by the proposed Eagle Project sulfide mine. This mine would be located on the Yellow Dog Plains near the headwaters of the Salmon Trout River and Yellow Dog River, potentially threatening two pristine rivers of the Huron Mountain area. The river was well known before the proposed mine, though, as it has ample recreational potentials along its length.

Google Image of Yellow Dog River

Yellow Dog River's route

Starting with two main branches in the McCormick Tract, southwest of the Yellow Dog Plains, the river begins as a series of lakes and swamps that once hosted the famous island fortress of the Bentleys and McCormicks. Because of these swamps, the river has a yellow/brown color during spring melt or heavy...

read more »

Setting up the Hiking Website

Even though my waterfalls site turned out to be a great way to chronicle adventures through wilderness, it has several areas that are lacking. The biggest area is the Google Maps functionality, which is shaky at best. It can only show the end points and major points along the route, but I didn't have enough data to actually upload the suggested route (waypoint by waypoint) for each journey. Also, I didn't have any way of displaying or archiving my other adventures with the waterfalls site, so I decided to make an individual web project: the hiking site.

The layout for this site was fairly simple: a full screen map with removable sidebar containing the hike and view options. Utilizing the jQuery framework would allow me to add the Google Maps pieces easily and use cool animation on different elements. The largest step was the data transfer. I only wanted to return xml, preferably formatted as KML, and use Javascript to parse the data and display it correctly.

Breaking it down to the user's view... A user will visit the main page and see a large map and a small sidebar. On the map will be icons, either for images or hikes, and the sidebar will contain links to different hikes and viewing options (view all points of interest v some points). Everything will be handled...

read more »