question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

instantsearch with Angular - How to Geo search ?

See original GitHub issue

Hi! I’m using InstantSearch Service with Algolia V4 and it’s working !

Now I’d like to filter results via IP.

Details :

My index has an attribute called “perimetre” By default, I’d like to GEO filter all results depending on user IP

I found this : https://www.algolia.com/doc/tutorials/geo-search/filter-results-around-a-location/#filtering-around-the-current-user-location

How can I use this with Angular ? Can I configure this directly in my Algolia Dashboard or should I implemente it in my code ? How ?

This is my hits.component.ts :

export class HitsComponent implements OnInit {
  // Define how your component state will look like,
  // and intialize it with an empty hits array
  state: { hits: {}[] } = { hits: [] };

  nbResultToShow = 8;

  constructor(private instantSearchService: InstantSearchService) { }

  ngOnInit() {
    // Create a widget which will call `this.updateState` whenever
    // something changes on the search state itself
    const widget = connectHits(this.updateState);

    // Register the Hits widget into the instantSearchService search instance.
    this.instantSearchService.search.addWidget(widget());
  }

  updateState = (state, isFirstRendering) => {
    // asynchronous update of the state
    // avoid `ExpressionChangedAfterItHasBeenCheckedError`
    if (isFirstRendering) {
      return Promise.resolve().then(() => {
        this.state = state;
      });
    }

    this.state = state;
  }
}

Thanks !

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
odecharettecommented, Nov 27, 2017

Hy @bobylito

Many thanks for your answer aroundLatLngViaIP is working !

How if I want to set the aroundRadius depending on data attribute ? I managed to set it in the service :

@Injectable()
export class InstantSearchService {
  search = instantsearch({
    appId: environment.algoliaAppId,
    apiKey: environment.algoliaApiKey,
    indexName: environment.algoliaIndexName,
    urlSync: environment.algoliaUrlSync,
    searchParameters: {
	    aroundLatLngViaIP: true,
	    aroundRadius: 40000 // 40km
	}
  });

  constructor() {}
}

But then, it’s the same radius for all However, I have an attribute called “perimetre” for each hit. How can use it ?

I’ll have a look on your Angular beta link, looks awesome 😃

0reactions
samousscommented, May 16, 2019

You can use the ais-configure widget to provide the location to aroundLatLng.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Geo search with Angular InstantSearch - Algolia
Leverage Geo search in your Angular InstantSearch app. ... We will see how we can leverage the geo search capabilities of Algolia with...
Read more >
Using Algolia Instantsearch with Angular 6. | by Zev | Medium
Algolia provides a set of parameters for filtering by facets, numbers or geo location. Angular InstantSearch packages those into a set of ...
Read more >
Algolia Angular InstantSearch buggy search-box
I was able to reproduce this behavior! It's related to the <ais-index indexName="index-name"> you have wrapping your hits component.
Read more >
angular-instantsearch - npm
Lightning-fast search for Angular apps, by Algolia.. Latest version: 4.4.0, last published: 20 days ago. Start using angular-instantsearch ...
Read more >
angular-instantsearch examples - CodeSandbox
Learn how to use angular-instantsearch by viewing and forking angular-instantsearch example apps on CodeSandbox. ... algolia-instantsearch-angular-geo.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found