This guide will show how to setup a View that shows list of contents in a Drupal 7 site that are filtered based on your visitor's city location with the use of Smart IP and Location contributed modules. Smart IP module is used to identify Drupal site visitor's geographical location based on his IP address and Location module is used to provide the field and expose views location filters.
Steps:
The following steps will list all the nodes with city location field stored content same as the value of my city detected by Smart IP.
-
Install Smart IP, Smart IP Views Bridge, Location, Location CCK, Ctools, Views and Views UI modules. For debug purposes, enable Device Geolocation module.
-
Setup a content type or use an existing content type (in this example we will use the existing "Basic page" content type) and add a new field with "Location" field type at http://www.yoursite.com/?q=admin/structure/types/manage/page/fields. Populate the field label with "Branch". Select "Location" from Type of data to store and click "Save" button.
-
At "Location" field settings > Locative Information > Collection Settings select "Allow" for the "City" and "Country" items and click "Save field settings" button.
Use the default values for succeeding setup settings of this field.
-
Create some "Basic page" content. Populate the "Title", "City" fields and select a country.
Note: Make sure that at one of your created node's city location field value matches your city geolocation that Smart IP has detected based on your IP. To check, enable the Device Geolocation's block at http://www.yoursite.com/?q=admin/structure/block.
-
Setup a new Views that will display the nodes under the content type with Location field you have setup earlier.
-
Add a filter criteria using "Location: City" filter.
-
Under the "Operator" select "Is equal to", type "smart_ip][location][city" in "Value" field and click "Apply" button.
-
Save your views.
-
Go to the page generated by the views you have created and you should see all the nodes with city location field stored content same as the value of your city detected by Smart IP.