Flutter Geocoding address

Viewed 1250

I want to get coordinates and full/real address depending on what I write on a TextField.

From the geocoding Flutter package, i can see the following example :

List<Location> locations = await locationFromAddress("Gronausestraat 710, Enschede");

So i have tried to write "Paris" and call locationFromAddress("Paris").
But it doesn't find any result because the address is malformed.

When i was developping my Android app with Google maps, i could even write "Lond" and it was finding "London" (I am not speaking about the PlaceAutoComplete API).

When you search a location you don't want to have to write the full address...

So how can i achieve this simple use case in Flutter ?

Thanks !

1 Answers

You can use try this package

Sample code:

    import 'package:geocoder/geocoder.dart';

    final query = "1600 Amphiteatre Parkway, Mountain View";
    var addresses = await Geocoder.local.findAddressesFromQuery(query);
    var first = addresses.first;
    print("${first.featureName} : ${first.coordinates}");
    
    // From coordinates
    final coordinates = new Coordinates(1.10, 45.50);
    addresses = await Geocoder.local.findAddressesFromCoordinates(coordinates);
    first = addresses.first;
    print("${first.featureName} : ${first.addressLine}");
Related