Solved

Looking for a Store Locator solution using php

Posted on 2009-03-30
6
288 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

757 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now