Why autocomplete matters at checkout
A free-text address box invites “near the big mosque, 3rd floor”. A courier then has to call the customer, and some parcels come back. Suggestions that resolve to a real place with coordinates remove most of that. The customer types four or five letters, taps the right building, and your order has a point on the map.
The GeoDesh endpoint is GET /v1/places/autocomplete. It takes the typed text as input and an optional lat/lng to prefer nearby results. Every suggestion comes back with placeId, mainText, secondaryText, description and a location, so you do not need a second call to get coordinates.
Keep your key off the phone
A key built into an app can be extracted from the package. Put a tiny proxy on your own server that adds the key and forwards the call. It also lets you rate-limit per user.
app.get('/api/address-suggest', async (req, res) => {
const input = String(req.query.q ?? '').slice(0, 80);
if (input.length < 3) return res.json([]);
const lat = Number(req.query.lat) || 23.78, lng = Number(req.query.lng) || 90.40;
const url = 'https://geodesh.com/v1/places/autocomplete?input=' + encodeURIComponent(input) + '&lat=' + lat + '&lng=' + lng;
const r = await fetch(url, { headers: { 'x-api-key': process.env.GEODESH_KEY } }).then((x) => x.json());
res.json((r.data ?? []).slice(0, 6).map((s) => ({ id: s.placeId, title: s.mainText, subtitle: s.secondaryText, lat: s.location?.lat, lng: s.location?.lng })));
});The Dart model and client
import 'dart:convert';
import 'package:http/http.dart' as http;
class AddressSuggestion {
final String id, title, subtitle;
final double? lat, lng;
AddressSuggestion({required this.id, required this.title, required this.subtitle, this.lat, this.lng});
factory AddressSuggestion.fromJson(Map<String, dynamic> j) => AddressSuggestion(
id: j['id'] as String,
title: j['title'] as String? ?? '',
subtitle: j['subtitle'] as String? ?? '',
lat: (j['lat'] as num?)?.toDouble(),
lng: (j['lng'] as num?)?.toDouble(),
);
}
class AddressApi {
AddressApi(this.base);
final String base; // your server, e.g. https://api.yourshop.com
Future<List<AddressSuggestion>> suggest(String q, {double? lat, double? lng}) async {
if (q.trim().length < 3) return [];
final uri = Uri.parse('$base/api/address-suggest').replace(queryParameters: {
'q': q,
if (lat != null) 'lat': '$lat',
if (lng != null) 'lng': '$lng',
});
final res = await http.get(uri).timeout(const Duration(seconds: 8));
if (res.statusCode != 200) return [];
final list = jsonDecode(res.body) as List<dynamic>;
return list.map((e) => AddressSuggestion.fromJson(e as Map<String, dynamic>)).toList();
}
}The widget, with debouncing
Each request is billed, so wait until the user pauses. 300 ms works well on phones, where typing is slower than on a keyboard.
import 'dart:async';
import 'package:flutter/material.dart';
import 'address_api.dart';
class AddressField extends StatefulWidget {
const AddressField({super.key, required this.api, required this.onPicked});
final AddressApi api;
final void Function(AddressSuggestion) onPicked;
@override
State<AddressField> createState() => _AddressFieldState();
}
class _AddressFieldState extends State<AddressField> {
final _ctrl = TextEditingController();
Timer? _debounce;
List<AddressSuggestion> _items = [];
bool _loading = false;
void _onChanged(String v) {
_debounce?.cancel();
_debounce = Timer(const Duration(milliseconds: 300), () async {
setState(() => _loading = true);
final items = await widget.api.suggest(v);
if (!mounted) return;
setState(() { _items = items; _loading = false; });
});
}
@override
void dispose() { _debounce?.cancel(); _ctrl.dispose(); super.dispose(); }
@override
Widget build(BuildContext context) {
return Column(children: [
TextField(
controller: _ctrl,
onChanged: _onChanged,
decoration: InputDecoration(
labelText: 'Delivery address',
suffixIcon: _loading ? const Padding(padding: EdgeInsets.all(12), child: SizedBox(width: 16, height: 16, child: CircularProgressIndicator(strokeWidth: 2))) : null,
),
),
..._items.map((s) => ListTile(
leading: const Icon(Icons.place_outlined),
title: Text(s.title),
subtitle: Text(s.subtitle),
onTap: () {
_ctrl.text = '${s.title}, ${s.subtitle}';
setState(() => _items = []);
widget.onPicked(s);
},
)),
]);
}
}Confirm the pin on a map
After a pick, show the point so the customer can check it. The quickest way in Flutter is a WebView with the GeoDesh embed page, which takes the key, centre and zoom as query parameters and accepts commands such as addMarker through atlasCommand.
https://geodesh.com/embed/map.html?key=YOUR_BROWSER_KEY&lat=23.7925&lng=90.4078&zoom=16If you only need a picture, a static map image is lighter: GET /v1/maps/static with lat, lng, zoom and a markers value renders a PNG you can show with Image.network.
Save what the courier needs
- The
placeId, so you can fetch details later. - The coordinates, for routing and the courier’s map.
- The text the customer saw, plus a free-text field for flat number and floor, which no map knows.
Costs and limits
Autocomplete costs ৳120 per 1,000 requests. With a 300 ms debounce and a three-letter minimum, a checkout usually makes three to five requests. For 10,000 orders a month that is about 40,000 requests or ৳4,800, inside the ৳5,000 free monthly credit. Prices are on the pricing page.
Testing tips
- Test with real addresses from your order history, in the spellings customers use.
- Pass the customer’s approximate location as
lat/lngwhen you have it; it makes suggestions much better in a city with repeated names. - Log which suggestion position customers pick. If they often scroll past the first, adjust the bias.
Measuring the result
Compare the share of orders with coordinates, the number of courier calls to customers and the return rate for a month before and after adding autocomplete. Those three numbers tell you whether the feature pays for itself, and they are easy to pull from most order systems.
What to store with each order
Save the suggestion’s placeId, its coordinates and the exact text the customer chose, plus a separate field for flat, floor and directions in the customer’s own words. Couriers need both: the point for navigation and the note for the last twenty metres. Keep the original typed text too; it helps support staff when a customer calls.
Handling errors and slow networks
Mobile data in Bangladesh can be slow or drop for a few seconds. Keep the last good suggestions on screen when a request fails, show a small retry hint rather than an error dialog, and never block checkout on autocomplete: a customer must always be able to type an address by hand and continue.
Frequently asked questions
Can I call GeoDesh directly from Flutter?
You can, but a key inside the app can be extracted. Use a server proxy for anything beyond a prototype.
How do I bias suggestions to a city?
Pass lat and lng of the customer or of your delivery area. Results near that point rank higher.
Does it work on Flutter web?
Yes. The same Dart code calls your proxy; the browser never sees your key.