fix: polyline decoding bug with large bounds and fix ulys API toll pricing precision
This commit is contained in:
@@ -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 [];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user