Edoardo
Edoardo

Reputation: 675

Get address and city name of a LatLng point using GoogleGeocoding Flutter

I am trying to get address and city name of a LatLng point using google_geocoding:

var googleGeocoding =
    GoogleGeocoding("MY_KEY");
var result = await googleGeocoding.geocoding.getReverse(LatLon(lat, lng));
print(result?.results?.first.formattedAddress.toString());

The result of the print:

Corso Italia, 22-24, 20122 Milano MI, Italy

I need to get only Corso Italia, the string before the comma and Milano, how can I get that?

I tried to use addressComponents, but I only got numbers (especially if I select locations in countries like Italy)

print(result?.results?.first.addressComponents?.first.longName.toString());

Upvotes: 0

Views: 390

Answers (1)

It may not be the most optimal but you could play with picking the string through the spaces and then make the string in such a way that you can have the sequence you want

Upvotes: 2

Related Questions