This is a Flutter Code which i tried to write...but since I am new to coding I need few help with code such as any shorter version i can make of the following code? or this is the best? This is the code...Also u can help with naming convention if u have better ones ;)
splitvar = comma seperated array String fetched from php-sql database
static haversine() async {
String splitvar = await Latlong1.latlong();
List<String> splittedString = splitvar.split(",");
int j = splittedString.length;
List<List<double>> moblatlong = List();
splittedString.removeLast();
List<double> splittedInt = splittedString.map(double.parse).toList();
for (int i = 0; i < j - 2; i = i + 3) {
List<double> row = List();
row.add(splittedInt[i]);
row.add(splittedInt[i + 1]);
row.add(splittedInt[i + 2]);
moblatlong.add(row);
}
print(moblatlong);
var usersInRange = new List();
final lat1 = x.894165;
final lon1 = y.0544283;
for (int i = 0; i < moblatlong.length; i++) {
var p = 0.017453292519943295; // Math.PI / 180
var a = 0.5 -
cos((moblatlong[i][2] - lat1) * p) / 2 +
cos(lat1 * p) *
cos(moblatlong[i][2] * p) *
(1 - cos((moblatlong[i][1] - lon1) * p)) /
2;
var k = 12742 * asin(sqrt(a));
print(k);
if (k <= 3) {
usersInRange.add(moblatlong[i][0].ceil());
// newlong.add(moblatlong[i]);
}
}
print(usersInRange);
}
//add haversine formula and check the radius
//filter out mobile numbers
//
//moblatlong = moblatlong[nth user][1]//Longitude = mobllatlong[nth user][2]
}```