getRequestMapbox method

void getRequestMapbox(
  1. String searchText
)

Implementation

void getRequestMapbox(String searchText) async {
  String url =
      'https://api.mapbox.com/geocoding/v5/mapbox.places/$searchText.json?&location=19.265138,73.072425&&country=IN&radius=10000&access_token=${widget.mapboxKey}&limit=5';

  //var response = await Locations().getSearchAddress(url);
  var response = await Locations().getSearchAddress(url,context);

  try {
    Map objGeocode = json.decode(response);

    if (locationList != null && locationList!.isNotEmpty) {
      locationList!.clear();
    }

    //pick the top records only
    int len = objGeocode['features'].length;
    if (len > 5) {
      len = 5;
    }
    for (int i = 0; i < len; i++) {
      OrderAddress orderAddress = OrderAddress();
      //ToastMessage().showToast(msg: '${objGeocode['features'][i]['place_name']}');
      orderAddress.loc = '${objGeocode['features'][i]['place_name']}';
      orderAddress.lat = '${objGeocode['features'][i]['geometry']['coordinates'][1]}';
      orderAddress.lng = '${objGeocode['features'][i]['geometry']['coordinates'][0]}';

      locationList!.add(orderAddress); //save the search data in list to select searched address from list
    }
    searchAddressProgressFlag = false;
    setState(() {});
  } catch (exc) {
    debugPrint(exc.toString());
  }
}