August 22, 2014
Hot Topics:
RSS RSS feed Download our iPhone app

Create Your Own Store Locator with Google Maps, PHP, and MySQL

  • February 1, 2010
  • By Jason Gilmore
  • Send Email »
  • More Articles »

This occasional series introducing various facets of the powerful Google Maps API has examined quite a few different features that are likely to appear in an enterprise web-based mapping implementation, ranging from calculating user-defined route distances to using the Google Maps API Geocoder to convert mailing addresses to their respective coordinates. In this installment, I discuss yet another feature that has become standard, particularly on the web sites of large retail chains: the "Store Locator."

The Store Locator feature provides web site visitors with an easy way to determine the location of nearby stores, typically done by first asking the visitor to provide his or her zip code. The site then consults a database containing all of the chain locations, somehow determining which stores reside in or around the visitor's zip code. The locator feature is also often enhanced by providing the user with an option to view stores residing within a specified radius of the provided zip code, such as 10 miles, 20 miles, or 100 miles. In this tutorial, I'll show you one way to create this feature using the Google Maps API, JavaScript, PHP, and a MySQL database.

The Location Table

Let's start by creating the table, which will contain information about each of the retail chain's outlets. For the purposes of example, I'll chart several locations of my favorite store, Barnes & Noble. This table, called location, contains each outlet's name, mailing address, and latitudinal/longitudinal coordinates. The coordinates were presumably saved to the database after geocoding the outlet's address using the Google Maps API geocoder. As I explained this in a previous article, I'll leave this task as an exercise for you and instead just present the location table structure:

CREATE TABLE location (
  id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
  name VARCHAR(100) NOT NULL,
  street1 VARCHAR(100) NOT NULL DEFAULT '',
  street2 VARCHAR(100) NOT NULL DEFAULT '',
  city VARCHAR(100) NOT NULL DEFAULT '',
  zip VARCHAR(10) NOT NULL DEFAULT '',
  state CHAR(2) NOT NULL DEFAULT '',
  latitude FLOAT(10,6) NOT NULL,
  longitude FLOAT(10,6) NOT NULL
);


With several stores in the database, I can plot their locations simultaneously on a map, as shown in Figure 1.


Figure 1. Plotting Ohio-based Barnes & Noble Locations:
I can plot all store locations in the database simultaneously on a map.


Tags: PHP, MySQL, JavaScript, Google Maps, Store Locator



Page 1 of 2



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Sitemap | Contact Us

Rocket Fuel