Implementation of Forward Geocoding (Coordinates from Address) in a Mobile Application
When the user enters an address in a delivery or registration field and the app needs coordinates — this is forward geocoding. The task is simple until you encounter partial inputs, typos, addresses without index, and buildings that Google doesn't know.
Typical Problems
CLGeocoder.geocodeAddressString(_:completionHandler:) on iOS takes any string and returns CLPlacemark array. The problem — no default region parameter: the string "Lenin 5" without city returns a placemark from Kazakhstan or nil altogether. Always pass CLRegion with center and radius corresponding to your target market.
On Android, Geocoder.getFromLocationName(address, maxResults) before Android 13 executes on main thread and easily causes NetworkOnMainThreadException if you forget to move to IO dispatcher or background thread. Another quirk: on emulator without Google Play Services returns empty list without error — a bug caught only on real device testing.
How We Implement
For accuracy, we use Google Maps Geocoding API directly: maps.googleapis.com/maps/api/geocode/json?address=…®ion=ru&language=en&key=…. Response contains geometry.location with coordinates and geometry.viewport — rectangle convenient to pass to CameraUpdate.newLatLngBounds() for proper zoom after map transition.
In Russian addresses case, we add DaData as first provider: their suggestions/api/4_1/rs/geocode/ better handles buildings, structures, and industrial zones. If DaData returned no results — fallback to Google. This two-level scheme covers 98%+ addresses.
On Flutter — geocoding package for platform variant or direct HTTP client (Dio) to Geocoding API. Cache results in Hive or sqlite with 24-hour TTL: same addresses rarely requested again, but cache saves API key quota.
Timeline: one to two days depending on number of providers and offline behavior requirements.







