San Diego Website Design & IT Services now in Virginia

Drupal Location Module for Two San Diego Web Design Projects

As fortune would have it, we had two websites in desperate need of a zipcode search. We really struggled with this module (and of course the requisite trying 10 other combinations first) and thought these instructions on how to integrate the Drupal Location Module might help other developers avoid the black hole:

1. Setting up Location Module with Zipcode Search for Drupal 6.13
Location: 6.x-3.1-rc1: http://drupal.org/project/location
GMap: 6.x-1.1-rc1: http://drupal.org/project/gmap
CCK: 6.x-2.5
Views: 6.x-2.6

2. Prelim with Google:
Create a Google account. If you are using GMail or Google Analytics you probably already have one.
Get a Google Maps API: http://code.google.com/apis/maps/signup.html
Save the API key as you will need it later.

3. In Drupal:
Activate both the GMap and Locations Modules
Activate the CCK and Views modules
(GMAP, GMAP Location, Location, Location Search, Node Locations)
Turn on Content (and any other CCK options you want)

4. Create a new Content type
For this example we’ll create a new Directory Listing content type: 

Name: Directory Listing
Type: directory_listing
Description: Directory Listing

5. Config for Database:
Import the zipcode database into the zipcodes table of your Drupal database use phpMyAdmin or command line
If using phpMyAdmin, make your Drupal database active by selecting it
Click the Import tab near the top of the phpMyAdmin interface.
Navigate to a local copy of the Location module, location/database/zipcodes.us.mysql
Click Open (or Choose), then the Go button
This may take a few minutes to import
Note: if you are using table prefixes you will need to add them to the zipcode file before importing.
Database prefixes are OK as is

6. Permissions for gmap_location module
Permissions- allow your admins and site editors to set user location
Config settings to show node map and show user map

7. Config for gmap_location module
Copy in your Google maps API Key:
Click the Save configuration button at bottom of page
Config for GMap Location-defaults OK

8. Permissions for location module:
Permissions: allow your admins and site editors to submit latitude/longitude

9. Config for location module:
Main settings tab-defaults OK
Map links tab-Uncheck all except United States: Google Maps
Geocoding tab-Click ON United States/Google Maps
Search options tab-defaults OK

10. Config for Collection settings:
–Location name
–Street location
–City
–State/Province,
–Postal code
–Country to Allow
–Additional Coordinate Chooser = Do not Collect
–Country Default = United States.

Under Display Settings, click the Hide the fields for Additional, Coordinate Chooser, Province name, Country name and Coordinates. Leave the other fields unchecked (not hidden) for now.
Click the Save content type button

11. Config Views:
Create a few sample Directory Listings with location information including zipcod

Add:
View name: location_by_zip
View Type: Node

Filters:
Node: Published (Yes)
Node: Type (Is one of: Directory Listing)
Location: Distance / Proximity
Country: United States
(Proximity Circular)

Expose:
Form mode: Postal Code (assume default country)

Fields:
Node: Title
Link this field to it’s node
Save, Preview

12. Testing:
Enter a zip code and a distance to search
Add a Page display to the view by choosing Page from the pop-up menu (left column)
Add a path for the page under Page settings by clicking on the word “None” in Path: None and entering the path
Click Save one more time to save this view
Enter the path you set in another browser or new browser window to test 

Verified by MonsterInsights