Skip to content
This repository has been archived by the owner on May 27, 2024. It is now read-only.

Exception when trying to parse geojson #30

Open
giaur500 opened this issue Aug 28, 2020 · 1 comment
Open

Exception when trying to parse geojson #30

giaur500 opened this issue Aug 28, 2020 · 1 comment

Comments

@giaur500
Copy link

I am trying to load and parse simple geojson:

Future<void> parse() async {
    final geojson = GeoJson();

    String json="{\n" +
        "    \"type\": \"Point\",\n" +
        "    \"coordinates\": [\n" +
        "        -105.01621,\n" +
        "        39.57422\n" +
        "    ]\n" +
        "}";

    await geojson.parse(json);

  }

and I am getting exception:

NoSuchMethodError: The getter 'iterator' was called on null.
Receiver: null
Tried calling: iterator

JSON is valid, what am I doing wrong?

@mblataric
Copy link

Hi,

I know this is old, but I stumbled on the same problem.
I am also having geoJson in format that does not include feature collection (another part of product, web application which is using OpenLayers was designed in such way).

I noticed geojson package refuses to parse json which does not include featureCollection - "iterator" null error led me to that conclusion.
So, I am doing a simple hack to fix this:

final wrappedFeature = """{
        "type": "FeatureCollection", 
        "features": [
          ${json}   // json here is in the format as in first post: { "type": ... 
        ]
      }""";

      try {
        await geojson.parse(wrappedFeature);
      } catch (e) {
        rethrow;
      }

     geojson.features.forEach((f) { ... /* do stuff with feature */ ... }

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants