How to get location lat and long from json in flutter

Viewed 226

I am retrieve value latitude and longitude from JSON in flutter.I try many thing but not git value of lat and long this is my json file

{ "results": [ { "geometry": { "location": { "lat": 19.2058593, "lng": 72.86612 } } } ] }

I try

>  var myMap = json.decode(data.toString());
>       var myName = myMap['results']['geometry']['location']['lat']

but not getting location values.please help me in flutter

1 Answers

Change it to :

 myName = myMap['results'][0]['geometry']['location']['lat']

This is because "geometry" is inside a list. It's at index[0] of this list, after accessing "results".

Related