Filter Drupal contents based on your visitor's city location in Views using Smart IP and Location modules

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.


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.

  1. Install Smart IP, Smart IP Views Bridge, Location, Location CCK, Ctools, Views and Views UI modules. For debug purposes, enable Device Geolocation module.

  2. 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 Populate the field label with "Branch". Select "Location" from Type of data to store and click "Save" button.

    Add location field

  3. At "Location" field settings > Locative Information > Collection Settings select "Allow" for the "City" and "Country" items and click "Save field settings" button.

    Location field collection settings

    Use the default values for succeeding setup settings of this field.

  4. Create some "Basic page" content. Populate the "Title", "City" fields and select a country.

    Create Basic page

    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

  5. Setup a new Views that will display the nodes under the content type with Location field you have setup earlier.

    Create views page

  6. Add a filter criteria using "Location: City" filter.

    Add views Location: City filter

  7. Under the "Operator" select "Is equal to", type "smart_ip][location][city" in "Value" field and click "Apply" button.

    Views Location: City filter configure

  8. Save your views.

  9. 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.

    Location views result page

Add new comment

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.