0

Please give me the solution for this. I have json data here

{
"id": "61e7e10f5c5677",
"travel_map": [
    {
        "odometer": 0,
        "coords": {
            "altitude": 150.1,
            "heading": -1,
            "latitude": 28.5799048,
            "speed": -1,
            "longitude": 77.3191382
        }
    },
    {
        "odometer": 0,
        "coords": {
            "altitude": 149.8,
            "heading": 315.43,
            "latitude": 28.5799129,
            "speed": 0.01,
            "longitude": 77.3191291
        }
    }
]
}

I need to filter latitude and longitude from these data in array like this

[LatLng(28.5799048, 77.3191382), LatLng(28.5799129, 77.3191291)]
4

2 Answers 2

1

Try this:

var travelMapList = yourJson["travel_map"] as List? ?? [];
var latLangList = travelMapList.map((e) => LatLng(e["coords"]["latitude"] ?? 0, e["coords"]["longitude"] ?? 0));
print(latLangList);

This will print

(Instance of 'LatLng', Instance of 'LatLng')
Sign up to request clarification or add additional context in comments.

1 Comment

It works. Thank you
0

Use Json to dart converter

if you get the response from api do like this

final parsedData=json.decode(response.body);
MyJsonToDartData data= new MyJsonToDartData.fromJson(parsedData);

now you can use the data as a object and access all the underlying values

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.