added from string constructor

This commit is contained in:
2026-06-19 14:02:11 +02:00
parent 9e950a1767
commit 383de6a33b
+9
View File
@@ -5,6 +5,15 @@ class LatLng {
LatLng(this.lat, this.lng); LatLng(this.lat, this.lng);
LatLng.empty() : lat = 0, lng = 0; LatLng.empty() : lat = 0, lng = 0;
/// must be formatted 'double, double'. For example 35.35217, 89.19659
factory LatLng.fromString(String latLng) {
final splitString = latLng.split(',');
final lat = double.parse(splitString[0].trim());
final lng = double.parse(splitString[1].trim());
return LatLng(lat, lng);
}
factory LatLng.fromJson(Map<String, dynamic> json) { factory LatLng.fromJson(Map<String, dynamic> json) {
return LatLng(json['lat'] as double, json['lng'] as double); return LatLng(json['lat'] as double, json['lng'] as double);
} }