We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

how to use MapShapeSource.network() with data from API Call (Post / Get from server)

I'm working with SfMaps and when I try to load geojson data from the local assets folder using the MapShapeSource.asset() property and everything works fine. But I'm having problems when I want to load geojson data as a result from api calling (GET / POST) using the http package flutter.

I believe this can be solved using MapShapeSource.network(), but am still confused about how to use it.

any kind of help is very much appreciated


// Function to load data json from API
Future<void> loadGeojsonData() async {
    setState(() => loading = true);
    try {
      final response = await http.post(
          Uri.parse("some url"),
          headers: {
            'Content-Type': 'application/json; charset=UTF-8',
          },
          body: body);
      if (response.statusCode >= 400) {
        throw Exception('statusCode=${response.statusCode}');
      }
      setState(() {
        loading = false;
        data = jsonDecode(response.body);
      });
    } catch (e) {
      setState(() => loading = false);
      debugPrint("Error load data: $e");
      return;
    }
  }


// Loadjson data from API in Map Shape Source.network() but not sure how to do it
dataSource = MapShapeSource.network(
    'url',
     shapeDataField: 'name',
  );

 


1 Reply

YG Yuvaraj Gajaraj Syncfusion Team January 24, 2023 01:11 PM UTC

Hi Afdul,


Greetings from Syncfusion.


We have checked your query at our end, and we would like to let you know that you can load the area shape JSON data from the web/network using the MapShapeSource.network() constructor available in the maps widget. We have shared the user guide documentation and sample below for your reference.


UG, https://help.syncfusion.com/flutter/maps/getting-started#from-network


Please check and get back to us if you require further assistance.


Regards,

Yuvaraj.


Attachment: f180130_8ea30858.zip

Loader.
Live Chat Icon For mobile
Up arrow icon