title: How to take XML data from API and extract data list from it
body: <p>I am calling an API that returns <code>XML</code> data</p>
  <p>I have a Class for the data to take the part of the data that I need.</p>
  <p>The API returns the <code>instances</code> fine but I am having trouble extracting the data List I need to then call a function (Which is tested and works) to place a <code>map marker</code>.</p>
  <p>I need to take the <code>lat, long</code> from the returned list <code>vehicleactivity</code> and use it</p>
  <p>This is the Class</p>
  <pre><code>import 'package:xml/xml.dart';
  
  class VehicleActivity {
    VehicleActivity({
      this.recordedAtTime,
      this.itemIdentifier,
      this.validUntilTime,
      this.longitude,
      this.latitude,
    });
  
    DateTime? recordedAtTime;
    String? itemIdentifier;
    DateTime? validUntilTime;
    double? longitude;
    double? latitude;
  
    factory VehicleActivity.fromElement(XmlElement vaElement) =&gt; VehicleActivity(
          recordedAtTime: DateTime.parse(
            vaElement.findElements('RecordedAtTime').first.text,
          ),
          itemIdentifier: vaElement.findElements('ItemIdentifier').first.text,
          validUntilTime: DateTime.parse(
            vaElement.findElements('ValidUntilTime').first.text,
          ),
          longitude: 
              double.tryParse(vaElement.findAllElements('Longitude').first.text),
  
          latitude:
              double.tryParse(vaElement.findAllElements('Latitude').first.text),
        );
  }
  </code></pre>
  <p>I am calling it with this API fetch</p>
  <pre><code>   Future &lt;VehicleActivity?&gt; fetchLiveLocations() async {
      var client = http.Client();
      VehicleActivity? vehicleActivity;
      
  
      
    try{
      var response = await client.get(Uri.parse(
        'https_call'));   
      if (response.statusCode == 200) {
  
    final doc = XmlDocument.parse(utf8.decode(response.bodyBytes));
    final vehicleActivity = doc
        .findAllElements('VehicleActivity')
        .map((e) =&gt; VehicleActivity.fromElement(e))
        .toList();
    print(vehicleActivity);
  
    }
   } catch(e) {
  
    print(&quot;Exception Happened: ${e.toString()}&quot;);
  }
  return vehicleActivity; 
  }
  </code></pre>
  <p>To then plot the marker I use this function, this is where the issue is.</p>
  <pre><code>Future&lt;void&gt; showMapMarkers() async {
      _unTiltMap();
  
      var vehicleActivity = await fetchLiveLocations();
    for (VehicleActivity vehicleActivity in vehicleActivity!) {
      GeoCoordinates geoCoordinates = GeoCoordinates (vehicleActivity.latitude, vehicleActivity.latitude);
      
  
      _addMapMarker(geoCoordinates, 1);
    
    }
  }
  </code></pre>
  <p>This is the issue</p>
  <pre><code>     The type 'VehicleActivity' used in the 'for' loop must implement Iterable.
  </code></pre>
  <p>On this line</p>
  <pre><code>    for (VehicleActivity vehicleActivity in vehicleActivity!) {
  </code></pre>
  <p>update - Function to plot not recognising (I use a <code>for</code> method for my Json, this could be the issue but have tried other options)</p>
  <pre><code>        Future&lt;void&gt; showMapMarkers() async {
      _unTiltMap();
  
      var vehicleActivity = await fetchLiveLocations();
    for (VehicleActivity vehicleActivity in vehicleActivity!) {
      GeoCoordinates geoCoordinates = GeoCoordinates (vehicleActivity.latitude, vehicleActivity.latitude);
      
  
      _addMapMarker(geoCoordinates, 1);
    
    }
  }
  </code></pre>