Algolia custom action with geolocation with max distance

Custom Code

Hi, I have this custom action taken from the video Algolia flutter flow Algolia.

I want to add a filter on the geolocation with a max distance. this is my code.

I did it in like 5 minutes with the firebase search, but with Algolia, it's another story...

// Automatic FlutterFlow imports
import '/backend/backend.dart';
import '/flutter_flow/flutter_flow_theme.dart';
import '/flutter_flow/flutter_flow_util.dart';
import '/custom_code/actions/index.dart'; // Imports other custom actions
import '/flutter_flow/custom_functions.dart'; // Imports custom functions
import 'package:flutter/material.dart';
// Begin custom action code
// DO NOT REMOVE OR MODIFY THE CODE ABOVE!

import 'dart:math';
import 'package:algoliasearch/algoliasearch.dart';

Future<dynamic> algoliaSearchAll(
String? query,
) async {
final client = SearchClient(
appId: 'HHYPKCBXB',
apiKey: 'my id key',
);

final queryHits = SearchForHits(indexName: 'companies', query: '$query');

// Define index name

final responseHits = await client.searchIndex(request: queryHits);
final hitsJson = responseHits.toJson();

final random = Random();
hitsJson['hits'] = (hitsJson['hits'] as List).toList()..shuffle(random);
return hitsJson;
}

What have you tried so far?

a bit everythingalgo

Did you check FlutterFlow's Documentation for this topic?
No
1
3 replies