validateLatitudeLongitude function

String? validateLatitudeLongitude(
  1. String? value
)

Validates Latitude and Longitude. Returns null if valid, or an error message string if invalid.

Implementation

String? validateLatitudeLongitude(String? value) {
  if (value == null || value.isEmpty) {
    return 'Please enter latitude and longitude';
  }
  // Basic check for latitude and longitude format
  if (!RegExp(
    r'^[-+]?([1-8]?\d(\.\d+)?|90(\.0+)?),\s*[-+]?(180(\.0+)?|((1[0-7]\d)|([1-9]?\d))(\.\d+)?)$',
  ).hasMatch(value)) {
    return 'Enter a valid latitude and longitude';
  }
  return null;
}