Hi everyone! I hope your hot summer day has been wonderful so far!!
I really have been hesitating to go outside because of this heat so to refresh my mind a little bit I’ve created this tutorial about how to create a store locator using php, mysql and google API.
The tutorial below is very straightforward and by the end of the tutorial you can download all the code.
I hope your enjoy and stay cool!!

Creating a store locator in PHP, MYSQL and Google API

What we need:
- Google API key. Please see link below:

http://code.google.com/apis/maps/signup.html

- PHP
- MYSQL

I will assume that you have a spreadsheet with all the address for your store locator so let’s the fun begins!!
First we need to create our Database to store all the address.
Please see scheme below:

CREATE TABLE IF NOT EXISTS `address` (
`ID` int(11) NOT NULL auto_increment,
`ST` varchar(300) NOT NULL,
`COUNTY` varchar(300) NOT NULL,
`CITY` varchar(300) NOT NULL,
`FACILITY NAME` varchar(400) NOT NULL,
`ADDRESS` varchar(400) NOT NULL,
`LOCATION` varchar(400) NOT NULL,
`ZIP` varchar(10) NOT NULL,
`PHONE` varchar(20) NOT NULL,
`FAX NUMBER` varchar(20) NOT NULL,
`Lat` varchar(200) NOT NULL,
`Lon` varchar(200) NOT NULL,
PRIMARY KEY (`ID`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3099 ;

Creating Store Locator PHP

Creating Store Locator PHP

Now you need to update the address that you have in your spreadsheet into your new database using the import tool.

Store locator php, mysql, google api

Store locator php, mysql, google api

After you uploaded all your address to the address database you will notice that the column Lat and Long is empty.
Be calm!!! We will work on that!!

First let’s configure our config.php file with our database connection and also you need to insert the state that you want to geocode and the google API key.

Store Locator PHP

What this code does is to insert latitude and longitude for all the addresses that you have that are located in that state that you inserted on you config.php file. Understand?!!
Yes it is very simple!

Now let’s execute the code geo.php.
And that is it! You have a latitude and longitude for all the address in your database.

Now we need to create a simple html form for our store locator.

After created a form we need to create a php code that will search for our store when you insert the zip code and select the mile range.
Please see image below. Don’t forget all the code can be downloaded so just pay attention for now!

After finishing the php code let’s test our form.
Open the form “form_locator.php”

Let’s type our zip code and select our mile range and Voila!!!!

Look all the results below:

Your store locator is completed!!!
I hope this tutorial can help you on your future projects!

Download your code here.