I validate the fonction of extract gps latitude and longitude with regex, but currently it's a String , and map_view accept only double
previous problem : how to display a regex result in flutter
I tried to use this to convert in double but it doesn't work
RegExp regExp = new RegExp( //Here is the regex fonction to extract long, lat r"maps:google\.com\/maps\?q=(-?[0-9]+.[0-9]+),(-?[0-9]+.[0-9]+)", ); var match = regExp.firstMatch(input); group1 = match.group(1); //match groupe seems to be an int group2 = match.group(2); var long2 = double.parse('$group1'); assert(long2 is double); var lat2 = double.parse('$group2'); assert(lat2 is double);
Use float() method or decimal() method to convert string to double in Python. Conversion of string to double is the same as the conversion of string to float.
Remove the quotes from
var long2 = double.parse('$group1');
to
var long2 = double.parse($group1);
You can also use
var long2 = double.tryParse($group1);
or to also accept numbers without fractions
var long2 = num.tryParse($group1)?.toDouble();
to not get an exception when the string in $group1
can not be converted to a valid double.
Why not use just group1 as in double.parse(group1)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With