fix: polyline decoding bug with large bounds and fix ulys API toll pricing precision

This commit is contained in:
ElPoyo
2026-06-04 16:40:50 +02:00
parent 555629760d
commit 0744665fe2
4 changed files with 91 additions and 35 deletions
+40
View File
@@ -0,0 +1,40 @@
import 'package:latlong2/latlong.dart';
List<LatLng> safeDecodePolyline(String encoded) {
if (encoded.isEmpty) return [];
try {
List<LatLng> poly = [];
int index = 0, len = encoded.length;
int lat = 0, lng = 0;
while (index < len) {
int b, shift = 0, result = 0;
do {
if (index >= len) break;
b = encoded.codeUnitAt(index++) - 63;
result |= (b & 0x1f) << shift;
shift += 5;
} while (b >= 0x20);
int dlat = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));
lat += dlat;
shift = 0;
result = 0;
do {
if (index >= len) break;
b = encoded.codeUnitAt(index++) - 63;
result |= (b & 0x1f) << shift;
shift += 5;
} while (b >= 0x20);
int dlng = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));
lng += dlng;
double finalLat = (lat / 1e5).clamp(-90.0, 90.0);
double finalLng = (lng / 1e5).clamp(-180.0, 180.0);
poly.add(LatLng(finalLat, finalLng));
}
return poly;
} catch (e) {
return [];
}
}