Search code examples
javascriptgeolocationalgolia

Geo searching with Algolia


I am implementing the geo search with algolia on the web. My code is as below:

var searchClient = algoliasearch(Algol_APP_ID, Algol_API_KEY);
var itemIndex = searchClient.initIndex('item');

function searchItems(keyword, lat, lng) {
  var prom;
  var searchObj = {
    query: keyword,
    aroundRadius: 200
  };

searchObj.aroundLatLngViaIP = true;

return itemIndex.search(searchObj)
    .then(function (content) {
      console.log(content);
    return content;
  })
}

If I comment out searchObj.aroundLatLngViaIP = true; it gets items but once I include it, I get back nothing from algolia. I think the problem is in the data, I do not have the the _geoloc parameter, which is in the tutorials, but I do not see anywhere in the documentation that, the lat and lng parameter must be encapsulated by that parameter. However, if someone can confirm that, that is the issue, is there a way I can alias a paramter in algolia to that parameter rather than rewriting all the data in my DB to use that paramter?


Solution

  • indeed using the _geoloc property is the only way to have geo localisation capabilities with Algolia. This is, today, not something configurable.

    You don't have to rewrite the whole data in your DB, you could only rewrite the one in Algolia if you are able to do that in your production flow/data.