GetByText method
Implementation
@override
Future<dynamic> GetByText({String? text}) async {
Response returnResponse;
try {
Map<String, String> headers = {
HttpHeaders.contentTypeHeader: "application/json",
'User-Agent':
'Mozilla/5.0 (compatible; MyApp/1.0; +https://example.com)',
};
String url = Configuration.GeoCodingSource.OSMConfig.NominatimURL!;
http.Response response = await http
.get(
Uri.parse(
"$url?q=$text&format=json&addressdetails=0&limit=10&polygon_svg=0"),
headers: headers)
.timeout(
const Duration(seconds: 60),
onTimeout: () {
throw FetchDataException('Request timeout');
},
);
returnResponse = Response(
_returnResponse(response), response.statusCode, response.headers);
} on SocketException {
throw FetchDataException('No Internet connection');
}
return returnResponse;
}