Test urlTemplate before loading map #2136
Unanswered
RedHappyLlama
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
Can anyone suggest a good way to test the map url, before loading a map? I recently got caught out by the OpenStreetMap User-Agent requirement with some very old code (see below). I was testing the basic map url in this old code, before loading the map, but even after the OpenStreetMap User-Agent requirement change, I was obviously still getting the 200 status code, but the map would fail to load.
http.Response response = await http.get(Uri.parse('https://tile.openstreetmap.org)).timeout(const Duration(seconds: 2), onTimeout: () { return http.Response('Error', 408);
I have tried to replicate the call I believe flutter_map makes to retrieve a tile picture, see code below. However even without the User-Agent specified in the headers, I still get a 200 status code. Would be good to exactly replicate the call flutter_map makes as the test, before loading the map or using an alternative url if there's an error. I'll obviously include User-Agent within the test and actual TileLayer, but I want to be able to run this test in case there's any other issues.
Response dioResponse = await dio .getUri<Uint8List>( Uri.parse('https://tile.openstreetmap.org/16/32305/21803.png'), options: Options(responseType: ResponseType.bytes), ) .timeout(const Duration(seconds: 2), onTimeout: () { return Response(statusMessage: 'Error', statusCode: 408, requestOptions: RequestOptions()); });
Any help would be greatly appreciated!! Thanks.
Beta Was this translation helpful? Give feedback.
All reactions