Search code examples
drupaldrupal-7drupal-modules

Search field - pre populate automatically with user location


I've seen some website, once you on the front page, it automatically populate the search field with your location. I want to implement the same thing for my directory site. One field, is for whatever they want to search for, and the second field is a location field for the user to enter the city or postcode they want to search on.

I want to pre-populate the location field, automatically once the user landed on front page. Any modules that I can use for this?


Solution

  • It will depend on which search engine/backend you use. Using Solr, you can use the Geolocation Field module in conjunction with Search API Location.

    The Search API Location module adds the possibility of location based searching to the Search API module (currently only Apache Solr is supported as the service class).

    Geolocation Field provides a field type to store geographical locations as pairs of latitude and longitude (lan,lng) as well as the necessary integration to display those locations through views, fields and using a number of different map providers.

    Once configured, you will be able to pre-populate the location field by hooking into your search form using hook_form_alter.