Solved

Looking for a Store Locator solution using php

Posted on 2009-03-30
6
298 Views
Last Modified: 2012-05-06
I am looking for a way to set up a post code search page.
To be more specific, I would like a database with a list of locations with postcodes .
I would then like to create a search of the postcode field and then have the page display the stores associated with this search.
Does anyone know an out of the box solution for something like this, or a way I can code this easily?
Thanks
0
Comment
Question by:Amanda Watson
  • 3
  • 3
6 Comments
 
LVL 14

Expert Comment

by:shobinsun
ID: 24018007
Hai,

1. You need a database .
2. You need the name of the "place" and the postcode for that "place" in the database for each "place" as a row.
3. Just search and see what's closest.

This is the simple method you can do.

regards.
0
 
LVL 11

Author Comment

by:Amanda Watson
ID: 24025527
Thanks for the comment.
I did figure out that I would be needing a database and search, but I am looking for a total solution for this?
Is there an out of the box solution for something like this?
Do you know of any ecommerce solutions that maybe do this?
0
 
LVL 14

Accepted Solution

by:
shobinsun earned 500 total points
ID: 24025765
Hello,

Here I am attaching an example for your need:

You can use $ _GET  in the "query()" function in ex2.php  for searching. Here uses a predefined value for searching.

Hope this will help you.

Regards.
ex2.php:
 
<?php
 
include 'class.geodata.inc.php';
 
 
 
$lookup = new EyeGeoData();
 
 
 
// Lookup postal code M5X 1J2
 
print_r($lookup->query('M5X 1J2'));
 
/*Array
 
(
 
    [PostalCode] => M5X1J2
 
    [City] => TORONTO
 
    [Province] => ON
 
    [Country] => CA
 
    [AreaCode] => 416
 
    [TimeZone] => 5
 
    [Coordinates] => Array
 
        (
 
            [Latitude] => 43.648306
 
            [Longitude] => -79.38224
 
        )
 
 
 
)*/
 
 
 
// Lookup zip code 90210
 
print_r($lookup->query('90210'));
 
/*Array
 
(
 
    [PostalCode] => 90210
 
    [City] => BEVERLY HILLS
 
    [Province] => CA
 
    [Country] => US
 
    [AreaCode] => 310
 
    [TimeZone] => 8
 
    [Coordinates] => Array
 
        (
 
            [Latitude] => 34.103131
 
            [Longitude] => -118.416253
 
        )
 
 
 
)*/?>
 
 
 
 
class.geodata.inc.php:
 
<?php
 
/**
 
 * EyeGeoData
 
 * Retrieve geographical information of a postal/zip/post code
 
 *
 
 * LICENSE: This source file is subject to the BSD license
 
 * that is available through the world-wide-web at the following URI:
 
 * http://www.eyesis.ca/license.txt.  If you did not receive a copy of
 
 * the BSD License and are unable to obtain it through the web, please
 
 * send a note to mike@eyesis.ca so I can send you a copy immediately.
 
 *
 
 * @author     Micheal Frank <mike@eyesis.ca>
 
 * @copyright  2008 Eyesis
 
 * @license    http://www.eyesis.ca/license.txt  BSD License
 
 * @version    v1.0.0 6/18/2008 3:13:34 PM
 
 * @link       http://www.eyesis.ca/projects/geodata.html
 
 */
 
 
 
class EyeGeoData
 
{
 
	const FEED = 'http://api.eyesis.ca/geo.xml';
 
 
 
	const KMS = 1;
 
	const MIS = 2;
 
 
 
	private $key = false;
 
	private $status_code, $lookups_left;
 
	public $result = false;
 
	public $out = 'xml';
 
 
 
	/**
 
	* Set a key for premium accounts
 
	* 
 
	* @param string $key Key provided by Eyesis for premium accounts
 
	*/
 
	public function setKey($key)
 
	{
 
 
 
		$this->key = $key;
 
 
 
	}
 
 
 
	/**
 
	* Get postal/zip code information
 
	* 
 
	* @param string $code The postal/zip code you want to lookup
 
	* @return mixed The result of the query, false on error
 
	*/
 
	public function query($code)
 
	{
 
 
 
		// Build the query
 
		$query = '?code=' . urlencode($code);
 
		if ($this->key)
 
			$query .= '&key=' . urlencode($this->key);
 
 
 
		$info = false;
 
 
 
		if ($this->out == 'xml')
 
		{
 
			// Use XML feed and SimpleXML
 
 
 
			if ($feed = new SimpleXMLElement(self::FEED . $query, NULL, true))
 
			{
 
 
 
				$this->status_code		= (integer) $feed->Request->StatusCode;
 
				$this->lookups_left		= (integer) $feed->Client->LookupsLeft;
 
 
 
				if ($this->status_code == 200)
 
				{
 
					$info = array (
 
						'PostalCode' 	=> (string) $feed->Details->PostalCode,
 
						'City' 				=> (string) $feed->Details->City,
 
						'Province' 		=> (string) $feed->Details->Province,
 
						'Country' 		=> (string) $feed->Details->Country,
 
						'AreaCode' 		=> (integer) $feed->Details->AreaCode,
 
						'TimeZone' 		=> (integer) $feed->Details->TimeZone,
 
						'Coordinates' => array (
 
							'Latitude' 		=> (float) $feed->Details->Coordinates->Latitude,
 
							'Longitude' 	=> (float) $feed->Details->Coordinates->Longitude
 
						)
 
					);
 
				}
 
 
 
			}
 
 
 
		} else {
 
			// Use Serialized feed
 
 
 
			if ($feed = file_get_contents(self::FEED . $query . '&out=php'))
 
			{
 
 
 
				$feed = unserialize($feed);
 
 
 
				$this->status_code		= (integer) $feed['PostalCode']['Request']['StatusCode'];
 
				$this->lookups_left		= (integer) $feed['PostalCode']['Client']['LookupsLeft'];
 
 
 
				if ($this->status_code == 200)
 
					$info = $feed['PostalCode']['Details'];
 
 
 
			}
 
 
 
		}
 
 
 
		$this->result = $info;
 
 
 
    return $this->result;
 
 
 
	}
 
 
 
	/**
 
	* Get the status code of the previous result
 
	* 
 
	* @return mixed
 
	*/
 
	public function getStatusCode()
 
	{
 
 
 
		return ($this->status_code) ? $this->status_code : false;
 
 
 
	}
 
 
 
	/**
 
	* Get the amount of lookups left
 
	* 
 
	* @return mixed
 
	*/
 
	public function getLookupsLeft()
 
	{
 
 
 
		return ($this->lookups_left) ? $this->lookups_left : false;
 
 
 
	}
 
 
 
	/**
 
	* Calculates the distance between this result and another GeoData object's result
 
	* 
 
	* @param GeoData $dest The object to compare to
 
	* @param integer $units The distance units
 
	* @return float
 
	*/
 
	public function calcDistance(EyeGeoData $dest, $units = self::KMS, $round = 3)
 
	{
 
 
 
		if (!$dest->result or !$this->result)
 
			trigger_error('Result empty; query either failed or has not been run', E_USER_ERROR);
 
 
 
		$dist = rad2deg(acos(sin(deg2rad($this->result['Latitude'])) * sin(deg2rad($dest->result['Coordinates']['Latitude'])) +  
 
			cos(deg2rad($this->result['Coordinates']['Latitude'])) * cos(deg2rad($dest->result['Coordinates']['Latitude'])) * 
 
			cos(deg2rad($this->result['Coordinates']['Longitude'] - $dest->result['Coordinates']['Longitude'])))) * 60 * 1.1515;
 
 
 
		// Convert to kms
 
		if ($units == self::KMS)
 
			$dist *= 1.609344;
 
 
 
		$dist = round($dist, $round); // Round off
 
 
 
    return (float) $dist;
 
 
 
	}
 
 
 
	/**
 
	* Convert this object to a string
 
	* 
 
	* @return string
 
	*/
 
	public function __toString()
 
	{
 
 
 
		if ($this->result)
 
			return print_r($this->result, true);
 
		else
 
			return "I've got nothing to say";
 
 
 
	}
 
}

Open in new window

0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 11

Author Comment

by:Amanda Watson
ID: 24025902
ok, great,
I will need to test it out and get back to you.
I don't have access to a database I can set up at the moment to test it.
Can I have an email for you so if I have any troubles I can contact you?
I will close this question as you have provided the solution
A
0
 
LVL 14

Expert Comment

by:shobinsun
ID: 24026146
Hello snowball77,

Here is my email-id : shobin@zbeanztech.com

Regards.
0
 
LVL 11

Author Comment

by:Amanda Watson
ID: 24026518
Great Thanks
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question